C++ beginner - simple outputs -
C++ beginner - simple outputs -
here have simple code serve calculator integers.
//calculator, michael lowry #include <iostream> using namespace std; void main () { int input = 0; int input2 = 0; int reply = 0; int operation = 0; cout << "enter first number" << endl; cin >> input; cout << "type 1 addition, 2 subtraction, 3 multiplication, or 4 division" << endl; cin >> operation; cout << "enter sec number" << endl; cin >> input2; if (operation = 1) { input + input2 == answer; } if (operation = 2) { input - input2 == answer; } if (operation = 3) { input * input2 == answer; } if (operation = 4) { input / input2 == answer; } cout << "your reply " << cout << reply << endl; scheme ("pause"); } when come in "1" 3 inputs, output "your reply 6121dbcc0". why reply variable messed up?
your output goes wrong. should have
cout << "your reply " << reply << endl; instead of
cout << "your reply " << cout << reply << endl; what happens writing outstream object cout output.
also comparing operators wrong, others have noted. should have == instead of = in if-statements , vice versa in assignment part. this:
if (operation == 2) { reply = input - input2; } c++
Comments
Post a Comment