Hai again!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Here is the code:
- Code: Select all
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int a;
cout << "Please input a number 1-5" << endl;
cin >> a;
switch(a)
{
case 1: cout << "You chose 1" << endl;
case 2: cout << "You chose 2" << endl;
case 3: cout << "You chose 3" << endl;
case 4: cout << "You chose 4" << endl;
case 5: cout << "You chose 5" << endl;
}
return 0;
}
In case you didn't notice the error is on lines 14-18.
- Code: Select all
case 1: cout << "You chose 1" << endl;
case 2: cout << "You chose 2" << endl;
case 3: cout << "You chose 3" << endl;
case 4: cout << "You chose 4" << endl;
case 5: cout << "You chose 5" << endl;
Oh noes! What do we do Argio?????????????????????????????
- Code: Select all
case 1: cout << "You chose 1" << endl;
break;
case 2: cout << "You chose 2" << endl;
break;
case 3: cout << "You chose 3" << endl;
break;
case 4: cout << "You chose 4" << endl;
break;
case 5: cout << "You chose 5" << endl;
break;
Come on Argio, how does that work???
I don't even need to make strange references to real life objects... Yay!
Well, thing of it this way...
Before I fixed the program, it did not know to stop running through the checks when it found the right one. This resulted in the following things:
If I chose 2 I would get 2-5
If I chose 5 i would get 5 :p
So a simple break statement is needed. When you place a break statements it tells the computer to skip the rest of the if or switch statements when it finds the correct one.

YAY!