Kinda Lost on Program

Ive been working a compression calculator and am struggling because after my program accepts the first input inside an "if" statement, it quickly skips through the second two inputs, I even included a system("pause") to attempt to slow things down.

On top of that issue the value of P1+P2+P3 (MTR) is always zero... Even if only the first number is excepted, MTR should not equal zero.

This is the section of code I am thinking things go wrong. Any help is greatly appreciated.

cout<< "Enter 1 to look at the engine library or 2 to begin the compression ratio calculator.";
cin>> x;

if (x==1) {
cout<<"Engine Code Displacement cc) Stock Compression"<<endl;
cout<<" JH 1781 8.5:1 "<<endl;
cout<<" GX 1781 9.0:1 "<<endl;
cout<<" RD 1781 9.0:1 "<<endl;
cout<<" HT 1781 10.0:1 "<<endl;
cout<<" RV 1781 10.0:1 "<<endl;
cout<<" PF 1781 10.0:1 "<<endl;
cout<<" PL (16v) 1781 10.0:1 "<<endl;
cout<<" PG 1781 8.0:1 "<<endl;
}

if (x==2)
{
cout<<"Enter the engine code of the Block you would like to use"<<endl;
cin>> P1;
cout<<"Enter the engine code for the Pistons/Connecting Rods/ Crank you would like to use"<<endl;
cin>> P2;
cout<<"Enter the engine code for the Head you would like to use"<<endl;
cin>> P3;
}
MTR= P1+ P2+ P3;

cout<<"The Compression Ratio you created is"<< MTR << "." <<endl;




return 0;
}


cin >> P1;
cin >> P2;
cin >> P3;

All attempt to read an int (guessing they are ints?) from the input stream.

The input stream consists of, for example:

32 <ENTER>

cin >> P1;

reads 32 and stops on the newline.

cin >> P2 fails to read an int because it sees the newline.
cin >> P3 fails for the same reason.

You have to read the newline.

See cin.ignore().

Topic archived. No new replies allowed.