Here is the scenario:
Write a c++ program that asks the user to input two numbers. If the first number entered is greater than the second number, the program should print " The first number is greater. Otherwise, it should print " The first number is smaller". Assume the user entered valid data. Here is the input value:
5 and 9. Is this the right way to type out the code?
//Declarations
int i=5;
char =if ;
char =else ;
cout<<" Enter a number:"<< endl;
If ( (5>9) && (9>5) )
cout<<"The first number is greater"<<endl;
else
cout<<" The first number is smaller"<<endl;
}
I am using dev c++. Its telling me that 18 6 D:\csc 133\katzlab5_a.cpp [Error] expected unqualified-id before '=' token,
19 6 D:\csc 133\katzlab5_a.cpp [Error] expected unqualified-id before '=' token
26 2 D:\csc 133\katzlab5_a.cpp [Error] 'else' without a previous 'if'
#include <iostream>
usingnamespace std;
int main()
{
//Declarations
int num1 = 0;
int num2 = 0;
cout << "Enter first number: ";
cin >> num1;
cout << endl <<" Enter second number: ";
cin >> num1;
cout << endl;
if (num1 > num2 )
{
cout << "The first number is greater" << endl;
}
else
{
cout << "The first number is equal or smaller" << endl;
}
return 0;
}