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.
#include <iostream>
#include <cctype>
#include <string>
usingnamespace 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);
}
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.
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;
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?
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.
#include <iostream>
#include <cctype>
usingnamespace 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);
constint 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);
}
{
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
constint 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
}
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 { )