Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Student major and status) Write a program that prompts the user to enter two ch

ID: 3672729 • Letter: #

Question

(Student major and status) Write a program that prompts the user to enter two characters and displays the major and status represented in the characters. The first
character indicates the major and the second is number character 1, 2, 3, 4, which indicates whether a student is a freshman, sophomore, junior, or senior. Suppose
the following chracters are used to denote the majors:
M: Mathematics
C: Computer Science
I: Information Technology
Here is a sample run:


Enter two characters: M1
Mathematics Freshman


Enter two characters: C3
Computer Science Junior


Enter two characters: T3
Invalid input

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
void main()
{

char str[2];
printf(" type 'EX' to exit");
while(1)
{
printf(" enter two characters:");
scanf("%s",&str);
if(str[0]=='M' && str[1]=='1')
printf(" Mathametics Freshman");
else if(str[0]=='M' && str[1]=='2')
printf(" Mathametics Sophomore");
else if(str[0]=='M' && str[1]=='3')
printf(" Mathametics junior");
else if(str[0]=='M' && str[1]=='4')
printf(" Mathametics Senior");
else if(str[0]=='C' && str[1]=='1')
printf(" Computer Science Freshman");
else if(str[0]=='C' && str[1]=='2')
printf(" Computer Science Sophomore");
else if(str[0]=='C' && str[1]=='3')
printf(" Computer Science junior");
else if(str[0]=='C' && str[1]=='4')
printf(" Computer Science Senior");
else if(str[0]=='I' && str[1]=='1')
printf(" Information Technology Freshman");
else if(str[0]=='I' && str[1]=='2')
printf(" Information Technology Sophomore");
else if(str[0]=='I' && str[1]=='3')
printf(" Information Technology junior");
else if(str[0]=='I' && str[1]=='4')
printf(" Information Technology Senior");
else if(str[0]=='E' && str[1]=='X') exit(0);
else printf(" invalid choice");

}
}