while with a string? Help please.

Hello. My objective with this program is to get a name, and two test scores from the user. Then, get the average of the two scores and print the user's name with the two test scores, and the average as well. The program is suppose to rerun for any number of times until "STOP" is entered for the name. I did what I thought was the correct way to do it, but the program does not exit the loop when I enter "stop" or "STOP". Any help would be great.

Thanks,

Wesley

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

int main()
{
	//delcaring variables
	string name;
	double test1;
	double test2;
	double average;
	double allAverage;

	//loop


	//get input
	while(name != "stop")
	{
		cout << "Please input your name: ";
		cin >> name;
		cout << endl << name << ", please input test one: ";
		cin >> test1;
		cout << endl << "now, please input test two: ";
		cin >> test2;
		cout << endl << endl;
		
		//calculations
		average = (test1 + test2)/2;


		//output
		cout << name << endl;
		cout << "Test one: " << test1 << endl;
		cout << "Test two: " << test2 << endl;
		cout << "Average: " << average << endl << endl;
	}

	cout << "You have exited." << endl;
		

	
	//end loop
}

The loop condition is only checked at the beginning of the loop so it will still ask you all the other questions after you have entered "stop" as name before it exits the loop.
Topic archived. No new replies allowed.