Help

Oct 14, 2014 at 5:52pm
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;
}
Oct 14, 2014 at 6:11pm
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
Oct 15, 2014 at 1:14pm
Thank you very much :) I didn't concentrated on the operator because in last tasks I was using & operator only.
Last edited on Oct 15, 2014 at 1:16pm
Oct 15, 2014 at 2:15pm
No problem :)
Topic archived. No new replies allowed.