using letters inside while() and If() conditions

Hello,

This program that I am trying to write is supposed to take in data from a user at a diving competition. This program is supposed to:

1. Prompt the user whether or not they want to enter diver information. 'y' to continue. Any other character to kill program.

(I put an
1
2
3
4
 if (prompt == 'y') 
{
return 0;
}


after

1
2
3
4
5
6
7

cout << "Enter information of diver? ";

cin >> prompt;

cout << endl;


but this just causes the program to end regardless of what I enter even if I enter 'y' so I removed it.)

2. If 'y' is entered then it asks for name of the diver and city they're from. this is just redisplayed at the very end.

3. Then we move on to the while() that says while (prompt ='y') then it continues to the next while statement.

5. This while(i2<=5) is all about prompting the user to enter a score. Input is validated. The if() inside compares the score entered to the lowest and highest scores so far and replaces them if the score is bigger or smaller.

6. After that the score counter (which measures number of scores entered) goes up once and then it loops back to the prompt the user to enter the second score. 5 scores in total are entered.

7. After i2=6 we exit that loop and then are prompted to enter degree of difficulty. The overall score for that particular diver is calculated by subtracting lowest and highest score from the total score and this number is multiplied by the degree of difficulty.

8. After that we display the divers name, city, and overall score. i1 (diver counter) is increased by one. Then we ask the user whether or not they want to enter another divers information. If yes it re-loops again prompting the user to enter 5 scores etc.

9. If user enters any character other then 'y' then we exit this loop and display number of divers (i1) and and the average score of all divers (average).

I can't get it to compile perhaps because I am using std::string improperly. please help.

For the first while() the program says

"Error 1 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)"

"Error 2 error C1903: unable to recover from previous error(s); stopping compilation"

" 3 IntelliSense: no operator "==" matches these operands
operand types are: std::string == char"

all these errors are with regard to while (prompt == 'y')

Please help! Really need some guidance since no one in real life will help me.


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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int i1 = 1;
	int i2 = 1;
	double score = 0;
	double scorenew;
	double highestscore=0;
	double lowestscore=0;
        string name;
	string city;
	char prompt;
	double dod=0;
	 double overall;
	double average;
	 double totaloverall = 0;

 	cout << "Diving competitor's scores/information organizer" << endl;

  	cout << "Enter information of diver? "; 
	
        cin >> prompt;

	cout << endl;
        
	
        cout << "Enter the divers name: ";

	cin >> name;

	cout << endl;

	cout << "Enter the diver's city: ";

	cin >> city;

	cout << endl;

	//prompt user to enter values


	while (prompt == 'y')//if user enters "y" the logic within is executed
	{
	while (i2 <= 5)
	{

	cout << "Enter score given by judge #" << i2;

	cin >> scorenew;

			//input validation for score 
        while (!(0 <= scorenew || scorenew <= 10) || cin.fail())

	{
	cout << "Invalid. Please enter a number 1-10: ";
	cin.clear();
	cin.ignore(10, '\n');
	}		
	score = score + scorenew;

	i2 = i2 + 1;

	if (score >= highestscore)
	{
	score = highestscore;
	}
	else if (score <= lowestscore)
	{
	score = lowestscore;
	}
	}

		
	cout << "Enter degree of difficulty: ";

	cin >> dod;

	cout << endl;

	while (!(1.0 <= dod || dod <= 1.8) || cin.fail())
	{
	cout << "Invalid. Please enter a number 1.0-1.8: ";
	cin.clear();
	cin.ignore(10, '\n');
	}

	overall = (score - (highestscore + lowestscore))*dod;

	cout << "Diver: " << name << ", City: " << city << "\n\n";

	cout << "Overall score was: " << overall;

	cout << "Wish to enter another diver? ";

	cin >> prompt;

	cout << endl;

	i1 = i1 + 1;

	totaloverall = totaloverall + overall;
	}

	average = totaloverall / i1;

	cout << "\tEvent Summary" << "\n\n";

	cout << "Number of divers participating: " << i1 << "\n\n";

	cout << "Average score of all divers: " << average;



	system("pause");

	return 0;

}
Last edited on
"error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)"
operand types are: std::string == char"

You cannot compare std::string and char
Thank shadowCODE

Ok i removed the line const char y='y';

When I do this and try to compile it says:
"Error 2 error C1903: unable to recover from previous error(s); stopping compilation"
"Error 1 error C2065: 'y' : undeclared identifier"
"3 IntelliSense: identifier "y" is undefined"

all with regard to:

while (prompt ==y)

Then i said string y;. Now it compiles!

Though it compiles when I input y for prompt, a name, then a city it totally skips the first while statement and goes straight down to line 108.

Last edited on
change prompt from std::string to char.
Also in line 46, y is not declared. Use, 'y' instead. while(prompt == 'y')
Topic archived. No new replies allowed.