we're learning functions in my C++ class, he's given us function main, we're to write sub-functions that'll complete the task libraries are just iostream. I need to return a value to be stored in the variable userInput, but i can't think of a way to do that without modifying the function main (which i'm not allowed to do) or adding a global variable(which i'm not allowed to do) I don't need the code, just a hint (sorry yahoo answers removes my spacing before my code)
// function get Input has already been declared
int main (void)
{
int userInput;
char letter grade;
char gradeSign;
cout << "input number between 1 and 100\n (an invalid value terminates the program)\n";
while (getInput (userInput))
{
//unrelavant code that uses the variable userInput
}
}
//function i've written so far
int getInput (int getInputVar)
{
cout << "Numeric grade: ";
cin >> getInputVar;
if (cin.fail() || getInputVar <0 || getInputVar > 100)
return 0;
else
return getInputVar;
2006-10-24
18:10:12
·
4 answers
·
asked by
duffusd
3
in
Computers & Internet
➔ Programming & Design
when i normally run the compiler, it ouputs a random number when i tell it to output userInput
2006-10-24
18:12:58 ·
update #1
i'm trying to assign the variable userInput in function main() the getInputVar, and i'm not allowed to modify function main() at all
2006-10-24
18:19:35 ·
update #2
the problem with all of your suggestions (thank you for them btw) is that they all revolve around using userInput as a global variable, its only available in function Main, and i can't change function main at all... and userInput isn't a global variable (i can't change that either) i think its impossible to do it, but my teacher insists that it is possible
2006-10-24
19:25:41 ·
update #3