BTW, here's what I ended up with:
Lab 7, part one
A program that uses pointers to get
an integer from user input as a
character value, reads it as an
integer value and passes it back to
the main function, where it is
displayed if it is a valid integer.
using namespace std;
int getInteger(int *num);
int input; /*holds the value of the user's input after it
is converted to an int value in function
int returnedValue; //acts as a test result from function getInteger
cout << "Enter an integer with a leading + or - sign." << endl;
/*calls the getInteger function and passes the address
of input to the pointer parameter in that function*/
/*tests whether the getInteger function found the input
to be valid, and if not, prints an error statement.*/
cout << "You did not input a valid integer. " << endl;
cout << "It must be a number with a + or - in front of it." << endl;
//displays the integer value returned by the getInteger function
cout << "The integer you entered is " << input << "." << endl;
//reads the user's input as a character value and determines whether it is valid
//parameter num points to the address of variable input, located in function main
int getInteger(int *num)
char c; //holds character value of user's input
int sign; //holds sign (positive or negative) of user's input
int rtrn; //holds value to be returned to function main
int value=0; //holds integer value of user's input
//gets user's input, skipping leading space
/*Checks to make sure the inputted character is a digit and the user has actually
entered something. If these are not true, the function will pass 0 back to main and
it will print an error message.*/
if (!isdigit(c) && !cin.eof())
/*Checks to make sure the first inputted character is either a '+' or a '-'.
If these are not true, the function will pass 0 back to main and it will
print an error message.*/
if (c!='+' && c!='-')
//Runs after the program has made sure the user input is valid.
//Checks whether the sign of the inputted integer is negative.
//If the sign is not negative, it must be positive.
//Retrieves the next character value from the input stream.
if(c=='-' || c=='+')
//As long as the character value in the input stream is a digit...
/*...value stores the value of the digit as an int and places
it in the proper place (i.e. hundreds, tens, ones)...*/
//...and then the program reads the next digit from the input stream.
/*Eventually, the absolute value of the entire number from the input
stream is "converted" to an int value and stored in variable value*/
/*After all digits have been read, value becomes positive or negative,
depending on the value of sign.*/
/*If the input stream contains a non-digit character after reading all
the digits, it puts this character back into the input stream to make
it available for later use.*/
//sets the value to be returned to c
/*Stores value of variable value in the memory space pointed to by p, which is
the variable input in function main. */
/*sends the value of rtrn back to function main, which gets stored in
variable returnedValue */