As title, I'm just a new C++ beginner (a.k.a noob), currently I have an exercise to determine the largest and the smallest from 3 different integers.
With this, I got the result as below when I entered 13, 27 and 14 :Code:// Read three different integers and hence determine the largest and the smallest integer #include <iostream> // program performs input and output using std::cout; // program uses cout using std::cin; // program uses cin using std::endl; // program uses endl // function main begins program execution int main() { int x; // first input integer int y; // second input integer int z; // third input integer cout << "Input three different integers: "; // prompt user for data cin >> x >> y >> z; // read three integers from user if ( x < y ) cout << "Smallest is " << x << endl; if ( x < z ) cout << "Smallest is " << x << endl; if ( y < x ) cout << "Smallest is " << y << endl; if ( y < z ) cout << "Smallest is " << y << endl; if ( z < x ) cout << "Smallest is " << z << endl; if ( z < y ) cout << "Smallest is " << z << endl; return 0; // indicate program executed successfully } // end function main
Instead, the result suppose to be like this (forgive me for skipping the parts looking for the largest number cuz it didn't work at this moment):Code:Smallest is 13 Smallest is 13 Smallest is 14
Geez, I'm stuck in this just at the beginning of my C++ programming learning, can anybody guide me and show me where I wrong. So far, I'd only know how to use the 'if' statement and those binary and relational operators including equality operators. ThanksCode:Smallest is 13 Largest is 27



LinkBack URL
About LinkBacks



