Validation Program problem!

So, I've only started learning C++ by myself, and have just finished the book "C++ Demystified" by Jeff Kent.
Then I started experimenting and wanted to make a calculator program for practice.
And I considered implementing a validation check to see if the equation is valid (i.e. mathematical operators and numbers only).

(I plan to allow users to use either 'x', 'X', or '*' as multiplication operators, by the way, so I try to include 'x' and 'X' as valid.)

Here goes my attempt :
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
#include <iostream>
#include <cctype>
using namespace std;

bool validCheck(char[]);

int main(void)
{
	cout << "Enter the equation :\n";
	char theEquation[20];
	cin.getline(theEquation, 20);
	validCheck(theEquation);
	if (validCheck(theEquation)==true)
		cout << "Equation is all valid.";
	else
		cout << "Equation is invalid.";
	int exitParameter;
	cin >> exitParameter;
	return 0;
}
bool validCheck(char eqArray[])
{
	bool resumeCheck=true;
	bool eqValidity=true;
	int indexer=0;
	do{
		if (eqArray[indexer]=='+')
			cout << "Equation has + as item number " << indexer << ".\n";
		else if (eqArray[indexer]=='-')
			cout << "Equation has - as item number " << indexer << ".\n";
		else if (eqArray[indexer]=='x')
			cout << "Equation has x as item number " << indexer << ".\n";
		else if (eqArray[indexer]=='X')
			cout << "Equation has X as item number " << indexer << ".\n";
		else if (eqArray[indexer]=='*')
			cout << "Equation has * as item number " << indexer << ".\n";
		else if (eqArray[indexer]=='/')
			cout << "Equation has / as item number " << indexer << ".\n";
		else if (isdigit(eqArray[indexer])==true)
			cout << "Equation has the number " << eqArray[indexer] << " as item number " << indexer << ".\n";
		else if (isspace(eqArray[indexer])==true)
			cout << "Equation has whitespace character as item number " << indexer << ".\n";
		else
		{eqValidity=false;
		resumeCheck=false;}
		if(resumeCheck!=false)
			indexer++;
	}while(resumeCheck==true);
	if (eqValidity=true)
		return true;
	else
		return false;
}


HOWEVER! No matter what I type, the program would only output "Equation is all valid". That, and none of the sentences "Equation has [something] as item number [something]" appear! It's as if the program skipped the whole series of nested if's! Can someone help tell me what's wrong?
I just ran your code, no changes and got the expected output, but I got it twice:
Enter the equation :
45x69
Equation has the number 4 as item number 0.
Equation has the number 5 as item number 1.
Equation has x as item number 2.
Equation has the number 6 as item number 3.
Equation has the number 9 as item number 4.
Equation has the number 4 as item number 0.
Equation has the number 5 as item number 1.
Equation has x as item number 2.
Equation has the number 6 as item number 3.
Equation has the number 9 as item number 4.
Equation is all valid.f

Process returned 0 (0x0)   execution time : 115.055 s
Press any key to continue.
Well, naturally. Because I executed the validCheck function twice, once as a single statement and the second inside the if statement. Did it out of curiosity on purpose.

Then the problem's with the debugger? What IDE are you using?
Can you please also test what happens if you enter an invalid equation?
Or are there any specific options you're using to run the debugger?
By the way, I'm using Visual C++ 2010 Express.
Topic archived. No new replies allowed.