I am at basic learning level. i got a task of programming
i have done it but the output is not well
The program is supposed to print salary is 275 if we input j
but it is continuously displaying salary is 400 even if we enter f as input
[/code]#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char status;
cout<<"Enter your status \n Enter j for junior or S for senior";
cin>>status;
if(status=='s'|'S')
{
cout<<"Salary is 400";
}
else if(status=='j'|'J')
{
cout<<"Salary is 275";
}
else
{
cout<<"Error";
}
getch();
}
char status;
cout << "Enter your status \n Enter j for junior or S for senior";
cin >> status;
if (status == 's' || status == 'S')
{
cout << "Salary is 400";
}
elseif (status == 'j' || status == 'J')
{
cout << "Salary is 275";
}
else
{
cout << "Error";
}
#include<iostream.h> should be #include <iostream>
void main() should be int main()
Chances are whatever source or website taught you to write this program, that it wasn't a very good one.
Edit:
#include<conio.h> is also not part of the c++ standard. Why do you have it there?
I am using turbo c++ for my program that supports the syntax in that way
i.e. [/code] #include<iostream.h> and [/code] void main()
using [/code] #include<conio.h> for [/code] getch();
I am using turbo c++ for my program that supports the syntax in that way
It's not your syntax that is the problem, it is your logic. Look at what TarikNeaj posted: if (status == 's' || status == 'S')
Then compare it to what you posted for the same input evaluation: if(status=='s'|'S')
What you are telling the program to do is to apply a bitwise OR operation to the characters 's' and 'S' and then determine if that is equal to what the user input. Whereas TarikNeaj is telling the program to evaluate whether either of the conditions are true.