same code gives different outputs on different computers. why does this happens?

My friends and i are working on a code that will convert an input number into the resistor colour code.This is my code.
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
#include <iostream>

using namespace std;

int main()
{
    int code;
    
    cout<<"Please insert resistor code.\nCode\t: ";
    cin>>code;
    
    switch(code)
    {
         case 0:
              cout<<"Colour\t: Black"<<endl;
              break;
         case 1:
              cout<<"Colour\t: Brown"<<endl;
              break;
         case 2:
              cout<<"Colour\t: Red"<<endl;
              break;
         case 3:
              cout<<"Colour\t: Orange"<<endl;
              break;
         case 4:
              cout<<"Colour\t: Yellow"<<endl;
              break;
         case 5:
              cout<<"Colour\t: Green"<<endl;
              break;
         case 6:
              cout<<"Colour\t: Blue"<<endl;
              break;
         case 7:
              cout<<"Colour\t: Violet"<<endl;
              break;
         case 8:
              cout<<"Colour\t: Gray"<<endl;
              break;
         case 9:
              cout<<"Colour\t: White"<<endl;
              break;
         default:
              cout<<"Resistor code should be 0-9."<<endl;   
              
    }   
    
    system ("Question1");
    return 0;
}


Our problem is that when we key in character to the program, our computers give us different outputs.

This is the output from my computer
Please insert resistor code.
Code    : w
Resistor code should be 0-9.
Please insert resistor code.
Code    : y
Resistor code should be 0-9.
Please insert resistor code.
Code    : a
Resistor code should be 0-9.
Please insert resistor code.
Code    :


And this is the output from my friend's computer
Please insert resistor code.
Code    : w
Colour  : Red
Please insert resistor code.
Code    : y
Colour  : Red
Please insert resistor code.
Code    : a
Colour  : Red
Please insert resistor code.
Code    :


On my computer, my code is working correctly, but on my friend's computer, my code is not working well. I would like to know what actually happened?

Oh ya, both of us are using Dev C++ program.

Thanks for the help.
I don't see any reason why his code would be doing that...

Although this line:
system ("Question1");

Don't use system() (except when you have to), and definitely don't use it to recurse...use a loop instead.
The problem is that code is undefined. If the read fails you don't know what code contains.

You need to do something like this
1
2
3
4
if(cin >> code)
{
    // now code must contain a valid integer
}

Topic archived. No new replies allowed.