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

Learning Outcomes: 1) Selection statements 2) Loops 3) Good programming practice

ID: 3748495 • Letter: L

Question

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, if the user enters more than 2 courses, your code shouldn' t exit. It should re-prompt the user to enter the number of courses again until 0,1 or 2 is entered. Same thing for the course nnbers: if the user enters one or more invalid course numbers, the program re-ask the user to enter the course numbers again... It is time to start talking about some good programming practices. Please watch this YouTube video before you start: https://www.youtube.com/watch?v- SpK1OTbouZQ

Explanation / Answer

#include <stdio.h>

#include <string.h>

int main(void) {

int CRN[5]; //storing CRN values in int array

CRN[0]=4587;

CRN[1]=4599;

CRN[2]=8997;

CRN[3]=9696;

char Course_Opted[10]; //will store course opted for

int CourseID_Opted[2]; //will store course ids opted for

char Course_Prefix[2][7];

strcpy(Course_Prefix[0], "MAT 236");

strcpy(Course_Prefix[1], "COP 220");

strcpy(Course_Prefix[2], "GOL 124");

strcpy(Course_Prefix[3], "COP 100"); //storing Course Prefix values in string array

int Credit_Hours[4] = {4, 3, 1, 3}; //storing Credit Hours values in int array

float Cost=35.00; //will hold total cost

int Student_Id; //will store Student's Id

int No_Courses;

printf("Enter the Students Id: ");

scanf("%d",&Student_Id);

printf(" Enter how many courses taken(up to 2): ");

scanf("%d",&No_Courses);

while(No_Courses<0 || No_Courses>2)

{

printf("Invalid number of courses. ");

printf("Please re-enter how many courses ( up to 2 ): ");

scanf("%d",&No_Courses);

}

if(No_Courses==0)

{

printf(" Thank you! ");

printf("PRESS ANY KEY TO CONTINUE...");

getchar(); //Enter any key to move forward

printf(" VALENCE COMMUNITY COLLEGE ");

printf(" ORLANDO FL 10101 ");

printf(" ************************* ");

printf(" Fee Invoice Prepared for student %d ",Student_Id);

printf(" Health & id fees %c %f ",'%',Cost);

printf(" ------------------------------------------------ ");

printf(" Total Payments %c %f ",'%',Cost);

}

else if(No_Courses==1)

{

printf(" Enter the course number: ");

scanf("%s",Course_Opted);

CourseID_Opted[0]=(Course_Opted[0]-'0')*1000+(Course_Opted[1]-'0')*100+(Course_Opted[2]-'0')*10+(Course_Opted[3]-'0'); //converting to number

int found=-1; //checking if course found or not

int i; //for iteration

for(i=0;i<4;i++)

{

if(CRN[i]==CourseID_Opted[0])

{

found=i;

}

}

while(Course_Opted[4]!='' || found==-1)

{

printf(" Sorry, Invalid course number(s)! ");

printf(" Enter the course number: ");

scanf("%s",Course_Opted);

CourseID_Opted[0]=(Course_Opted[0]-'0')*1000+(Course_Opted[1]-'0')*100+(Course_Opted[2]-'0')*10+(Course_Opted[3]-'0'); //converting to number

for(i=0;i<4;i++)

{

if(CRN[i]==CourseID_Opted[0])

{

found=i;

}

}

}

printf(" Thank you! ");

printf("PRESS ANY KEY TO CONTINUE...");

getchar(); //Enter any key to move forward

printf(" VALENCE COMMUNITY COLLEGE ");

printf(" ORLANDO FL 10101 ");

printf(" ************************* ");

printf(" Fee Invoice Prepared for student %d ",Student_Id);

printf(" 1 Credit Hour = %c120.25 ",'%');

printf(" CRN CREDIT HOURS ");

printf(" %d %d %c %f ",CRN[found],Credit_Hours[found],'%',120.25*Credit_Hours[found]);

printf(" Health & id fees %c %f ",'%',Cost);

Cost=Cost+120.25*Credit_Hours[found]; //calculating total cost

printf(" ------------------------------------------------ ");

printf(" Total Payments %c %f ",'%',Cost);

}

else

{

printf(" Enter the 2 course numbers seperated by - :(like 2356-8954) ");

scanf("%s",Course_Opted);

CourseID_Opted[0]=(Course_Opted[0]-'0')*1000+(Course_Opted[1]-'0')*100+(Course_Opted[2]-'0')*10+(Course_Opted[3]-'0'); //converting to number

CourseID_Opted[1]=(Course_Opted[5]-'0')*1000+(Course_Opted[6]-'0')*100+(Course_Opted[7]-'0')*10+(Course_Opted[8]-'0'); //converting to number

int found1=-1; //checking if course found or not

int found2=-1; //checking if course found or not

int i; //for iteration

for(i=0;i<4;i++)

{

if(CRN[i]==CourseID_Opted[0])

{

found1=i;

}

if(CRN[i]==CourseID_Opted[1])

{

found2=i;

}

}

while(Course_Opted[4]!='-' || found1==-1 || found2==-1 || found1==found2)

{

printf(" Sorry, Invalid course number(s)! ");

printf(" Enter the course number: ");

scanf("%s",Course_Opted);

CourseID_Opted[0]=(Course_Opted[0]-'0')*1000+(Course_Opted[1]-'0')*100+(Course_Opted[2]-'0')*10+(Course_Opted[3]-'0'); //converting to number

CourseID_Opted[1]=(Course_Opted[5]-'0')*1000+(Course_Opted[6]-'0')*100+(Course_Opted[7]-'0')*10+(Course_Opted[8]-'0'); //converting to number

for(i=0;i<4;i++)

{

if(CRN[i]==CourseID_Opted[0])

{

found1=i;

}

if(CRN[i]==CourseID_Opted[1])

{

found2=i;

}

}

}

CourseID_Opted[0]=(Course_Opted[0]-'0')*1000+(Course_Opted[1]-'0')*100+(Course_Opted[2]-'0')*10+(Course_Opted[3]-'0'); //converting to number

CourseID_Opted[1]=(Course_Opted[5]-'0')*1000+(Course_Opted[6]-'0')*100+(Course_Opted[7]-'0')*10+(Course_Opted[8]-'0'); //converting to number

printf(" Thank you! ");

printf("PRESS ANY KEY TO CONTINUE... ");

getchar(); //Enter any key to move forward

printf(" VALENCE COMMUNITY COLLEGE ");

printf(" ORLANDO FL 10101 ");

printf(" ************************* ");

printf(" Fee Invoice Prepared for student %d ",Student_Id);

printf(" 1 Credit Hour = %c120.25 ",'%');

printf(" CRN CREDIT HOURS ");

printf(" %d %d %c %f ",CRN[found1],Credit_Hours[found1],'%',120.25*Credit_Hours[found1]);

printf(" %d %d %c %f ",CRN[found2],Credit_Hours[found2],'%',120.25*Credit_Hours[found2]);

printf(" Health & id fees %c %f ",'%',Cost);

Cost=Cost+120.25*(Credit_Hours[found1]+Credit_Hours[found2]); //calculating total cost

printf(" ------------------------------------------------ ");

printf(" Total Payments %c %f ",'%',Cost);

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote