Advice on how to deal with if and else statement

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'

Not sure what I am doing.
Last edited on
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
#include <iostream>

using namespace 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;
}

Last edited on
after I compiled it only said enter first number..how do I get everything to show?
im sorry ran
Topic archived. No new replies allowed.