Author Topic: I need some help with a void function and exit(1)  (Read 4451 times)

Offline stormtroopers

  • Single posting newcomer
  • *
  • Posts: 2
I need some help with a void function and exit(1)
« on: November 05, 2011, 01:28:39 am »
I'm studying for an exam and trying the practice problem in the book.  I keep getting an error with a void fctn, the code is below:

void readdata(int num[], int &n)
{
    cout << "Enter the number of marks> ";
    cin >> n;
    if (n > 0 && n <= SIZE)
        cout << "There are " << n << " marks" << endl;
    else {
        cout << "Invalid number of marks" << endl;
        exit(1);
    }
    for (int count = 0; count < n; count++)   {
        cout << "Enter a mark> ";
        cin >> num[count];
        cout << num[count] << endl;
    }
    return;
}

This is the error msg:

E:\Users\...\Practice Programs\20111104_Prog7.cpp||In function 'void readdata(int*, int&)':|  <--- HA! my error msg is not happy with me!
E:\Users\...\Practice Programs\20111104_Prog7.cpp|41|error: 'exit' was not declared in this scope|

What am I doing wrong?  I'm litterally copying code from the book and didn't make any mistakes in that sense.  Also, I'm very new to programming so I've done all that "my" programming allows me to do.

Thanks in advance!

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: I need some help with a void function and exit(1)
« Reply #1 on: November 05, 2011, 02:31:23 am »
Quote
This is NOT a general programming board.
If you did not realize, you are asking in the wrong place.

Try http://www.cplusplus.com/forum/ or http://www.daniweb.com/software-development/cpp/8.

Offline stormtroopers

  • Single posting newcomer
  • *
  • Posts: 2
Re: I need some help with a void function and exit(1)
« Reply #2 on: November 05, 2011, 04:47:49 am »
Ahh, thanks.  All I saw was the Help title.  It was such a pain to get a user name on this site I'm almost as sad as the error message that Code Blocks gave me! Thanks again.