Code problem

Pages: 12
I am having issue with my code. The menu options will are not being compared and are coming up undefined. I have included the code. Have been working on this for a week now and am starting to get frustrated.
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
 
#include <iostream>
#include <cctype>
#include <string>

using namespace std;

int main()

{	
	int highnum (0);
	int lownum(100);
	int limit(0);
	char choice();
	int counter(0);

	{
	int menu;
		cout<<   "A - Find the largest number with a known quantity of numbers. ";
		cout<<   endl;
		cout<<	 "B - Find the smallest number with an unknown quantity of numbers. ";
		cout<<   endl;
		cout<<	 "C - Quit";
		cout<<	 endl;
		cout<<	"Enter your choice. ";
		cin >>	choice;
		cout<<	endl;
	}

	{
           if (choice == a)
		while (counter <= limit);
		 cout << " How many numbers would you like to compare? ";
		 cout << endl;
		 cin >> limit;
	 	 cin >> highnum;
		 int (counter + 1);
		 if (highnum > highnum)
		 cout << highnum;	 
		
	}


	
	{
	
	if (choice == b)
		cout << "Enter your numbers. ";
		cin >> lownum;
		if (lownum < lownum)
		cout << lownum;
	}
	


	
	if (choice == c)
	return (0);
}
Last edited on
Your while loop syntax is incorrect. Check that and see if you can figure out that problem.
That was suppose to be if while like the rest of the possible menu variable comparisons.
might i suggest a switch statement.
Can you post it as a code block so I can give line numbers? And are the opening bracket (before int main;) and the closing bracket (after cout<< endl;) a bit useless?
This is the error I am getting.
1>c:\users\eric\documents\visual studio 2010\projects\goodman-menuprogram\goodman-menuprogram\goodman-menuprogram.cpp(36): error C2065: 'a' : undeclared identifier
1>c:\users\eric\documents\visual studio 2010\projects\goodman-menuprogram\goodman-menuprogram\goodman-menuprogram.cpp(52): error C2065: 'b' : undeclared identifier
1>c:\users\eric\documents\visual studio 2010\projects\goodman-menuprogram\goodman-menuprogram\goodman-menuprogram.cpp(62): error C2065: 'c' : undeclared identifier
not sure how to set a cod block for here kind of new to this stuff only been trying it for 4 weeks and the last three nothing has worked out correctly.

never mind figured it out.
Last edited on
I think you have to change "cin >> char (choice);" to "cin >> char choice;"
and if that doesn't work you should declare char choice; and then do cin >> choice;
well none of it worked choice needs to be set by the user in the menu so the program will do that options code a b or c.
I think I'm kinda getting retarded, because I tried serveral things with thisone, but I keep getting stuck. Why does it ask for a declaration of a, b and c?
I have no idea changed it to numbers and now none of the loops run their code, but the menu will at least display.
Your brackets are wrong. They should be used like this:

1
2
3
4
5
6
7
8
9
if(condition)
{
//Code to execute if condition is true
}
//Same for while loops:
while(Condition)
{
//Code
}
you are comparing a choice and some variable named a...

you have to do it this way

if(choice == 'a')

if(choice == 'b')

since a b and c are characters, you must compare to a character, the way you have it you are comparing it to an un declared variable a b and c
and what blacksheep said
Aah that's what I was looking for, the little ' thingy's. Totally forgot about them.
Thanks going to try it now
Still not working new code. When it does work it wont let me enter more than one number per loop either now and then moves on to the next menu option and does not go back to the menu. I feel so lost.
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
#include <iostream>
#include <cctype>
using namespace std;

int main()
//set variables
{	
	int highnum (0);
	int lownum(0);
	int limit(0);
	char choice(); 
	int counter(0);
	int num;
	
	
		cout<<   "A - Find the largest number with a known quantity of numbers. ";
		cout<<   endl;
		cout<<	 "B - Find the smallest number with an unknown quantity of numbers. ";
		cout<<   endl;
		cout<<	 "C - Quit";
		cout<<	 endl;
		cout<<	"Enter your choice. ";
		cin>>  choice;
		cout<<	endl;
	

		{
	while(choice == 'a')
	
		while (counter <= limit);
		 cout << " How many numbers would you like to compare? ";
		 cin >> limit;
		 cout << endl;
		 cout<< "Enter your number ";
		 cin >> num;
		 int (counter + 1);
		}
		{
		if (num > highnum)
		cout << "your highest number was ";
		 cout << highnum << endl; 
	while (choice == 'b')
		
	while(lownum<= -999);
		const int sentinel(lownum = -999);
		cout << "Enter your numbers. ";
		cin >> num;
		while (num < lownum)
		cout << "Your lowest number was ";
		cout << lownum << endl;
		}
		{
	if (choice == 'c')
		cout << "thank you for playing. " << endl;
		}
	cin.get();
	cin.get();

	return (0);
}
Last edited on
Hang on, how did you get this to even compile?
char choice(); // Get rid of the parentheses

What were you trying to do here?
int (counter + 1);
If you want to increment counter, use
++counter;

And I'm also not sure what you wanted here (I formatted the code so you can see what's wrong):
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{
    if (num > highnum)
        cout << "your highest number was ";

    cout << highnum << endl; // This is outside of the if

    while (choice == 'b') // Potential infinite loop here
        while(lownum<= -999)
            ; // Empty statement

    const int sentinel(lownum = -999); // Unused variable
    cout << "Enter your numbers. ";
    cin >> num;

    while (num < lownum) // Infinite loop, since you don't ever change num in it
        cout << "Your lowest number was ";

    cout << lownum << endl; // This is outside of the while
}
Last edited on
now I can not access the res of the code beyond the menu.
Okay, look at this (it's the same thing you have; I just reformatted it to make the problems stand out) and see if you can figure out what's wrong with this.
(I'm already kinda telling you below...)

1
2
3
4
5
6
7
8
9
10
11
12
13
{ // This { doesn't really have any meaning currently
    // Infinite loop
    while(choice == 'a')
        while (counter <= limit)
            ; // Empty statement - just keeps looping and looping...

    cout << " How many numbers would you like to compare? ";
    cin >> limit;
    cout << endl;
    cout<< "Enter your number ";
    cin >> num;
    int (counter + 1); // Does nothing
} // See above (what I said about the { ) 
Pages: 12