I started writing a program that, so far, looks like the following:
int main()
{
double grades;
char answer[5];
do {
?cout << "Please input the grades you want averaged:" << endl;
?cin >> grades;
?ifstatement(grades, answer);
} while (answer[0] == 'y');
cout << "Your grades were: " << grades << endl;
return 0;
}
void ifstatement(double grades, char answer[5])
{
if ?(grades >= 0 && grades <= 100)
?{cout << "Do you wish to input another grade? (y/n) "; cin >> answer;}
else
?{cout << "Sorry, the grade must be between 0 and 100. Try again: "; cin >> grades;
?ifstatement(grades, answer);}
}
So far, it does its job. I just coded it this far to see if my functions work well together. What I want to do now is to allow the user to keep inputting values as they're needed.
For example, he inputs 5, and then the program asks if he wants to put it another one, and he says yes... and inputs 7.
Now the values he has are 5 and 7.
The program is to take the average of whatever values the user inputs. How can I make the program remember all the values the user inputs?
Question
Ravager
I started writing a program that, so far, looks like the following:
int main() { double grades; char answer[5]; do { ?cout << "Please input the grades you want averaged:" << endl; ?cin >> grades; ?ifstatement(grades, answer); } while (answer[0] == 'y'); cout << "Your grades were: " << grades << endl; return 0; } void ifstatement(double grades, char answer[5]) { if ?(grades >= 0 && grades <= 100) ?{cout << "Do you wish to input another grade? (y/n) "; cin >> answer;} else ?{cout << "Sorry, the grade must be between 0 and 100. Try again: "; cin >> grades; ?ifstatement(grades, answer);} }So far, it does its job. I just coded it this far to see if my functions work well together. What I want to do now is to allow the user to keep inputting values as they're needed.
For example, he inputs 5, and then the program asks if he wants to put it another one, and he says yes... and inputs 7.
Now the values he has are 5 and 7.
The program is to take the average of whatever values the user inputs. How can I make the program remember all the values the user inputs?
Link to comment
Share on other sites
15 answers to this question
Recommended Posts