Using basic C, please help write this code. Learning Outcomes: 1) Selection stat
ID: 3747542 • Letter: U
Question
Using basic C, please help write this code.
Learning Outcomes: 1) Selection statements 2) Loops 3) Good programming practices (watch the YouTube video. See link below) Your c program for the following problem should run exactly as shown in the sample runs, including format and indentation. Name your c file as project3.c The main difference between this project (project3) and project2 is the use of Loops. Please pay attention to how the code should run-see sample runs For example, af the user enters more than 2 courses, your code shouldn't exit It should re-prompt the user to nter the number of courses again until 01 or 2 is entered Same thing tor the course numbera: E the user enters one o more invalid course numbers, the program re-ask the usez to enter the course numbers againExplanation / Answer
// Program to calculate fee invoice
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
int sid,nocourse,c1,c2;
char c;
int course[4]={4587,4599,8997,9696};
int chour={4,3,1,3};
char cprefix[4][20]={“MAT 236”,”COP 220”,”GOL 124”,”COP 100”};
const float hid=35.00;
const float cfee=120.25;
printf(“ Enter the student ID:”);
scanf(“%d”,&sid);
printf(“ Enter how many courses taken ( up to 2)”);
scanf(“%d”,&nocourse);
//If number of courses=2
if(nocourse==2)
{
input:
printf(“ Enter the 2 courses taken separated by –(like 2356-8954)”);
scanf(“%d%c%d”,&c1,&c,&c2);
for(i=0;i<4;i++)
{
if(c1==course[i])
{
for(j=0;j<4;j++)
{
if(c2==course[j])
{
printf(“ thank you”);
printf(“ PRESS ANY KEY TO CONTINUE… ”);
getch();
printf(“ VALENCE COMMUNITY COLLEGE ”);
printf(“ ORLANDO FL 10101 ”);
printf(“ ***************************************** ”);
printf(“ Fee invoice prepared for student v%d ”,sid);
printf(“ 1 credit hour =$%.2f ”,cfee);
printf(“ CRN CREDIT HOURS”);
printf(“ %d %d $%.2f”,c1,chour[i],chour[i]*cfee);
printf(“ %d %d $%.2f”,c2,chour[j],chour[j]*cfee);
printf(“ Health and ID fee $%.2f”,hid);
printf(“ *************************************************”);
printf(“ Total payment $%.2f”,(chour[i]*cfee)+(chour[j]*cfee)+hid);
goto end;
}
}
}
}
if(i==4 || j==4)
{
printf(“ Sorry, invalid course number(s):”);
goto input;
}
}
//If number of courses=1
else if(nocourse==1)
{
in:
printf(“ Enter the courses number: ”);
scanf(“%d”,&c1);
for(i=0;i<4;i++)
{
if(c1==course[i])
{
printf(“ thank you”);
printf(“ PRESS ANY KEY TO CONTINUE… ”);
getch();
printf(“ VALENCE COMMUNITY COLLEGE ”);
printf(“ ORLANDO FL 10101 ”);
printf(“ ***************************************** ”);
printf(“ Fee invoice prepared for student v%d ”,sid);
printf(“ 1 credit hour =$%.2f ”,cfee);
printf(“ CRN CREDIT HOURS”);
printf(“ %d %d $%.2f”,c1,chour[i],chour[i]*cfee);
printf(“ Health and ID fee $%.2f”,hid);
printf(“ *************************************************”);
printf(“ Total payment $%.2f”,(chour[i]*cfee)+hid);
goto end;
}
}
if(i==4)
{
printf(“ Sorry, invalid course number(s):”);
goto in;
}
}
//If number of courses=0
else if(nocourse==0)
{
printf(“ thank you”);
printf(“ PRESS ANY KEY TO CONTINUE… ”);
getch();
printf(“ VALENCE COMMUNITY COLLEGE ”);
printf(“ ORLANDO FL 10101 ”);
printf(“ ***************************************** ”);
printf(“ Fee invoice prepared for student v%d ”,sid);
printf(“ Health and ID fee $%.2f”,hid);
printf(“ *************************************************”);
printf(“ Total payment $%.2f”,hid);
goto end;
}
end:getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.