2. Program that accepts as input a salesperson status. If status is s or S, the senior person salary should be displayed; if status is j or J, the junior person salary should be displayed.
Chapter 5:
Conditional Structures
Programming Exercise
Problem # 2:
Senior salesperson is paid Rs. 400 a week, and a junior salesperson is paid Rs. 275 a week. Write a program that accepts as input a salesperson's status in the character variable status. If status is 's' or 'S', the senior person's salary should be displayed; if status is 'j' or 'J', the junior person's salary should be displayed, otherwise display error message.
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main ()
{
char status;
cout<<"Enter your status\nEnter \'s\' or \'S\' for senior person\'s salary\nEnter \'j\' or \'J\' for junior person\'s salary."<<endl;
cin>>status;
switch (status)
{
case 's':
case 'S':
cout<<endl<<"Your salary is Rs.400 per week.";
break;
case'j':
case 'J':
cout<<endl<<"Your salary is Rs.275 per week.";
break;
default:
cout<<endl<<"Invalid input.";
}
return 0;
}
#include<conio.h>
using namespace std;
int main ()
{
char status;
cout<<"Enter your status\nEnter \'s\' or \'S\' for senior person\'s salary\nEnter \'j\' or \'J\' for junior person\'s salary."<<endl;
cin>>status;
switch (status)
{
case 's':
case 'S':
cout<<endl<<"Your salary is Rs.400 per week.";
break;
case'j':
case 'J':
cout<<endl<<"Your salary is Rs.275 per week.";
break;
default:
cout<<endl<<"Invalid input.";
}
return 0;
}
Let me know in the comment section if you have any question.
Previous Post:
1. Program that accepts a character and determines whether the character is a lowercase letter.
Comments
Post a Comment