Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switch Problem 2

Status
Not open for further replies.

VisaManiac

Technical User
Aug 12, 2001
14
0
0
US
I apologize for bringing in such a simple question, but I just enrolled in a beginners C++ class, and here's one of our questions...what am I doing wrong? It won't resolve.

#include <iostream>
using namespace std;

int main()
{
int a;
int x;
cout << "Please enter a number between 1 through 4";
cin >> a;

switch(a)
{
case a = '1':
cout << x += 5 << endl;
break;
case a = '2':
cout << x += 10 << endl;
break;
case a = '3':
cout << x += 16 << endl;
break;
case a = '4':
cout << x += 34 << endl;
break;
default:
cout << "You did not enter a number of 1 through 4." << endl;
}

system("PAUSE");

return 0;
}

A little guidance would be greatly appreciated!
 
Code:
case a = '1':
You're mixing switch and if syntax.
It should look like this:
Code:
case 1:
 
See also += and << operators precedences in your book.
Think about x value in you x += ... statements...
Good luck!
 
Awesome! Both had valid suggestions and resolved my statements! Thanks so much guys!
 
(To Miros;) see the 2nd line in my post above...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top