//this program is like this type
//hope you will understand
#include <iostream>
using namespace std;
void main()
{
int decider=0;
int num1, num2;
cout << "Input 2 integers separated by a space. " << endl;
cin >> num1 >> num2;
if (num1>num2)
decider=1;
else if (num1<num2)
decider=2;
switch (decider)
{ case 2 :
{cout << num1 << " " << "is the minimum number while" << " " << num2 << " " << "is the maximum number." << endl;
break;}
case 1 :
{cout << num1 << " " << "is the maximum number while" << " " << num2 << " " << "is the minimum number." << endl;
break;}
default : { cout << "The input is invalid." << endl;}
}
system("pause");
}
The value of this expression will be true (1) when both num1 and num2 are non-zero and false (0) otherwise. Perhaps you should be looking at the greater-than (>) or less-than (<) operator.
I am really new to programmin myself(2nd year in college) , so this might be wrong or right, if i understand your question. I will let you figure out where the ; and {} go. Like I said I am new, but this is where i would start.
Your switch statement is incorrect to begin with. I think what you asking is for the user to input two numbers and have your program compare the two and tell the user which is larger/smaller compared to the other.
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main()
{
int num1, num2, num3;
cout << "Input 2 integers separated by a space. " << endl;
cin >> num1 >> num2;
if (num1 > num2)
num3=1;
elseif (num2 > num1)
num3=2;
elseif (num1 == num2)
num3=3;
switch(num3)
{
case 1:
cout << num2 << " is the minimum number while " << num1 << " is the maximum number." << endl;
break;
case 2:
cout << num1 << " is the minimum number while " << num2 << " is the maximum number." << endl;
break;
case 3:
cout << num1 << " is equal to " << num2 << endl;
break;
default:
cout << "The input is invalid." << endl;
}
system("PAUSE");
return 0;
}
Now to wait for my question in the forums to be replied to. Like standing in line for a roller coaster. It sucks to wait so long for a ride that will last only minutes. Well i guess that could be my sex life too. Joys of being married. :(