Boolean function not working

Hi,

Anyone could spare the time to look at my program and see why the boolean goes straight to boolGood, can't fix it

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>
using namespace std;

int main() 
{
	bool inputGood = false;
	string message;
	int i = 0;
	while (inputGood == false)
	{
		cout << "Please enter a message CONTAINING only letters and spaces" << endl;
		getline(cin, message);
		for(i = 0; i < message.size();i++)
		{	
		if(message[i] > 122  message[i] < 97 && message[i] != 32)
			{
				inputGood = false;	
				cout << "Input bad";
			}
		else
			{
				inputGood = true;
				cout << "Input good";
			}
		}
	}
	return 0;
}
Hi,

This:

while (inputGood == false)

can be written:

while (!inputGood)

message.size() returns a std::size_t type, so you should use that type for variable i.

Line 15 is missing a relational operator.

The compiler can tell you about these things, make sure you have warning levels set sufficiently high.

Good Luck !!
Thanks been stuck on it for ages
Topic archived. No new replies allowed.