Input on loop

I'm trying to make a loop that will allow a user to enter in as many numbers as they would want to, until they enter in a key word like done or -1. The end goal of what I am doing is to make a grading program that would allow you to enter in anywhere from 1 grade to 100 for example.

Not entirely sure how I would be able to do something like this, I'm trying to teach myself loops and this was just an idea I had after looking at someone's grading program that calculated the grade of 3 different user entered numbers.

I have the very beginning of the code here:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <conio.h>

using namespace std;

void welcome_message() { //Display message to user

	cout << "Hello user today we are going to calculate your grades from class" << endl;
	cout << "This program will average your grades together into one letter grade" << endl;
	cout << "Please enter in your whole grade i.e 95.7" << endl;
	cout << "Our grading structure is as follows: A = 90-100, B = 80-89, C = 70-79, D = 60-69, F = 0-59" << endl;
	cout << "If you have entered in all of the grades you wish to enter, please enter in 'done'" << endl;
}

int user_input() {
	
	
}

int main() {
	welcome_message();
	user_input();

	_getch();
	return 0;
}



Once I get this part done, I was going to add in an option at the end which would allow the user to enter in more grades if they wished, or to close the program. I was going to use a switch for this, and then call user_input() once this part is made.

I've never done anything like this before, generally what I have been writing is a set amount, like enter in your three grades and it'll calculate your average.

Any input on this would be greatly appreciated, I'm not exactly looking for code more so ideas.

Thank you.
Last edited on
Something like this should do:
1
2
3
4
double score{};
do {
    std::cin >> score;
} while( score != -1.0 )

You may want to store the scores in an array or preferably a vector.
https://www.tutorialspoint.com/cplusplus/cpp_stl_tutorial.htm
Last edited on
I was actually just playing around with vectors right now, I haven't used them in a long time so hopefully once I get a handle on them I'll be able to get this finished.

Thank you.
Topic archived. No new replies allowed.