### Simple Program small number

Hello everyone, I am trying to write a program that reads in three integers and determines and prints the smallest number numerically in the group.

Help! What am I doing wrong!

#include <iostream>
using namespace std;
int main () {
int num1, num2, num3;
cout << "Enter 3 integers: ";
cin: num1, num2, num3;
if ( num1 < num2 || num3 )
cout << "The smallest value among // num1 // num2 // num3 is // num1";
if ( num2 < num1 || num3 )
cout << "The smallest value among // num1 // num2 // num3 is // num2";
if ( num3 < num1 || num2 )
cout << "The smallest value among // num1 // num2 // num3 is // num2";
return 0;
}

cin: num1, num2, num3;

should be

cin >> num1 >> num2 >> num3;

if ( num1 < num2 || num3 )

should be

if ( num1 < num2 || num1 < num3 )
Also you could economize your coding if it interests you by doing this:

 ``12345678`` ``````cout << "The smallest value among // num1 // num2 // num3 is // "; if ( num1 < num2 || num 1 < num3 ) cout << "num1"; else if ( num2 < num1 || num2 < num3 ) cout << "num2"; else if ( num3 < num1 || num3 < num1 ) cout << "num2";``````
Hey everyone, thanks for the help.. once more thing..

I am trying to get it to say "The smallest value among <a>, <b>, and <c> is <x>" (where <a>, <b>, <c>, and <x> are replaced by the actual values.) but it seems like I am messing up cout formatting. :(

Thanks

#include <iostream>
using namespace std;
int main () {
int num1, num2, num3;
cout << "Enter 3 integers: ";
cin >> num1 >> num2 >> num3;
if ( num1 < num2 || num1 < num3 )
cout << "The smallest value among // num1 // num2 // num3 is // num1";
if ( num2 < num1 || num2 < num3 )
cout << "The smallest value among // num1 // num2 // num3 is // num2";
if ( num3 < num1 || num3 < num2 )
cout << "The smallest value among // num1 // num2 // num3 is // num3";
return 0;
}
 ``12`` ``````cout << "The smallest value among " << num1 << ", " << num2 << ", and " << num3 << " is " << num1 << endl;``````
This is outputting data but I need it to output in cout the smallest of the 3 numbers after going through the if statements.
Try to do it yourself. As an advice define one more variable that will contain the minimum.

By the way your function is incorrect because it will not find the smallest if at least two of three numbers are equal to each other and less than the third number.
Last edited on
Topic archived. No new replies allowed.