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

Your C program for the following problem should run exactly as shown in the samp

ID: 3747136 • Letter: Y

Question

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. 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 numbers: if the user enters one or more invalid course numbers, the program re-ask the user to enter the course numbers again. ..

Explanation / Answer

//project3.c

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#define MAX_COURSE 2

//helper methods

int check_valid_course(int *,int,int);

void format_out(int *,int *, int *, int ,int);

int main(){

//course number

int CRN[4] = {4587,4599,8997,9696};

//credit hours

int credit_hours[4] = {4,3,1,3};

int num;

int student_id;

printf("Enter the Students Id: ");

scanf("%d",&student_id);

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

scanf("%d",&num);

//checking the number of course

while(num<0 || num > MAX_COURSE){

printf("Invalid number of courses. ");

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

scanf("%d",&num);

}

int input_course[2];

int c_n=0;

if(num==1){

while(1){

printf("Enter the course number: ");

scanf("%d",&c_n);

//checking the course number

if(check_valid_course(CRN,4,c_n)){

input_course[0]=c_n;

break;

}

else{

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

}

}

}

else if(num==2){

while(1){

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

char c[15];

int a0=0;

scanf("%s",c);

char* token = strtok(c, "-");

while(token!=NULL){

c_n = atoi(token);

if(check_valid_course(CRN,4,c_n)){

input_course[a0++] = c_n;

token = strtok(NULL,"-");

}

else{

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

a0=0;

break;

}

}

if(a0>1)break;

}

}

//calling format_out for printing the formatted output

format_out(CRN,credit_hours,input_course,num,student_id);

}

int check_valid_course(int *crn,int l,int n){

int i;

for(i=0;i<l;i++){

if(crn[i]==n){

return 1;

}

}

return 0;

}

void format_out(int *CRN,int *hours, int *input_courses, int num, int student_id){

float>

int i,j;

float total=0;

printf(" ");

printf(" VALENCE COMMUNITY COLLEGE ");

printf(" ORLANDO FL 10101 ");

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

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

if(num>0){

printf(" 1 Credit Hour = $%f ",one_credit_hr);

printf(" CRN CREDIT HOURS ");

}

for(i=0;i<num;i++){

int h;

for(j=0;j<4;j++){

if(input_courses[i]==CRN[j]){

h=hours[j];

break;

}

}

float cost = (float)h * one_credit_hr;

total += cost;

printf("%*d %d $ %.2f ",15,input_courses[i],h,cost);

if(i==num-1){

printf(" ");

}

}

printf(" Health & id fees $ %.2f ",35.00);

total += 35.0;

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

printf(" Total Payements $ %.2f ",total);

}//end

//OUTPUT

Enter the Students Id:
3424
Enter How many courses taken(up to 2):
3
Invalid number of courses.
Please re-enter how many courses (up to 2):
1
Enter the course number:
4522
Sorry, invalid course number (s)!

Enter the course number:
4599

VALENCE COMMUNITY COLLEGE
ORLANDO FL 10101
*************************

Fee Invoice Prepared for student V3424

1 Credit Hour = $120.250000

CRN CREDIT HOURS
4599 3 $ 360.75


Health & id fees $ 35.00

--------------------------------------
Total Payements $ 395.75

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