Help

I am given an assignment to make, here the question is.
Write a program to take two numbers and a character as an input. Ask the users at run time to print larger one if the character input is "L", and smaller number if the character input is "S".
Its running without errors. But I don't know where the problem is I can't get the results.

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<cstdlib>
#include<iostream>
using namespace std;
int main()
{
    int n1,n2;
    char ch;
    cout<<"Enter first number: ";
    cin>>n1;
    cout<<"Enter second number: ";
    cin>>n2;
    cout<<"Enter any character: ";
    cin>>ch;
    if(ch=='L' && ch=='l')
    {if(n1>n2)
    cout<<n1;
    else if(n2>n1)
    cout<<n2;}
    else if(ch=='S' && ch=='s')
    {if(n1<n2)
    cout<<n1;
    else if(n2<n1)
    cout<<n2;}
    system("pause");
    return 0;
}
your first if statement checks if ch is equal to both 'L' and 'l' when it should be OR
if (ch == 'L' || ch == 'l')
same goes with the if statement on line 19
Thank you very much :) I didn't concentrated on the operator because in last tasks I was using & operator only.
Last edited on
No problem :)
Topic archived. No new replies allowed.