C++ program to find greatest of two numbers using Switch case conditional statement.
I am finding error's & output is in correct. can any one help me.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
int main()
{
clrscr();
int First, Second;
cout<<"Enter two Integers."<<endl;
cout<<"First"<<setw(3)<<": ";
cin>>First;
cout<<"Second"<<setw(3)<<": ";
cin>>Second;
switch ((First > Second))
{
case 0:
cout<<"First is Greater than Second."<<endl;
break;
};
switch ((First < Second))
{
case 0:
cout<<"Second is Greater than First."<<endl;
break;
};
switch ((First == Second))
{
case 0:
cout<<"First and Second are Equal."<<endl;
break;
};
getch();
return 0;
}
#include <iostream>
int main()
{
//Declared the variables.
int first, second;
//Asked for the numbers.
std::cout << "What is the first number?\n";
std::cin >> first;
std::cout << "What is the second number?\n";
std::cin >> second;
//Set up the switches.
switch(first>second)
{
case 1:
std::cout <<"The first number is bigger.\n";
break;
};
switch(first<second)
{
case 1:
std::cout <<"The second number is bigger.\n";
break;
};
switch(first==second)
{
case 1:
std::cout <<"The numbers are equal.\n";
break;
};
//Paused the compiler before it exited. i left out any text because it seemed pointless, and there are two
//because the "Enter" from the last "std::cin" was being read by the "std::cin.get()".
std::cin.get();
std::cin.get();
return 0;
}
the only thing that i saw was that since you were asking for it to compare two things, in a Boolean manner, case 0: was meaning "if the statement is false: output this". i just changed it to case 1: and to reverse it. :-) hope this helped!