PLEASE HELP

Program is about to compare any two numbers input. Then, it will display whether the number is minimum or maximum. Use switch statement.

#include <iostream>
using namespace std;
void main()
{
int num1, num2;

cout << "Input 2 integers separated by a space. " << endl;
cin >> num1 >> num2;

switch (num1 && num2)
{ 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");
}




WHAT AM I DOING WRONG HERE????????? PLEASE
I guess I would say rephrase your question. It makes no sense.
You cannot compare these two numbers ...which one is minimum and which is maximum
This was the question given to me. Then how? PLEASE can you show me?
//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");
}
Last edited on
switch (num1 && num2)

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 understand. Yeah, lecturer can't really speak english.

Tqvm
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;

class Comparator

void main()

 int num1, num2;
 int output;

cout << endl << "please enter first number." << endl;
cin >> num1;
cout << endl << "please enter second number." << endl;
cin >> num2;

if (num1 > num2)

cout << endl << "Number 1 is the highest number";

 else if (num2 > num1)
 
 cout << endl << "Number 2 is the highest number";
 



---OR----

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>

using namespace std;

class Comparator

void main()

 int num1, num2;
 int output;

cout << endl << "please enter first number." << endl;
cin >> num1;
cout << endl << "please enter second number." << endl;
cin >> num2;

if (num1 > num2)

 numb1 >> output;

 else if (num2 > num1)
 
 numb2 >> output;
 cout << endl << "The highest number is" << output << endl;

 system("pause")

std::exit;
 



Last edited on
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    int num1, num2, num3;

    cout << "Input 2 integers separated by a space. " << endl;
    cin >> num1 >> num2;
    
    if (num1 > num2)
    num3=1;
    else if (num2 > num1)
    num3=2;
    else if (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;
}
THANKS YALL. SOLVED THE QUESTION EDI :D
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. :(
Last edited on
Topic archived. No new replies allowed.