Ive tried just making a lot of lines of different variables for entering courses, then the courses being assigned to credits and output on a receipt. But instead of having the 300+ lines of switches I wanted to make a switch function that I could call. I figured I would make a for loop to run the switch function based on the amount of courses the person chose, but when I run it the code seems to just run forever without even hitting a return 0 to end the program. Any tips for calling the function or if im doing it poorly?
int studentId, var, i;
float first;
int course, course1, course2;
float second, amount;
float credit1, credit2, credit3, credit4, credit5, credit6, credit7, credit8;
float paymentA, paymentB, paymentC, paymentD, total;
float creditA, creditB;
char *a;
void courseInfo(int myCourse){
switch(myCourse)
{
case 4587:
credit1 = 4;
a = "MAT 236";
break;
case 4599:
credit1 = 3;
a = "COP 220";
break;
case 8997:
credit1 = 1;
a = "GOL 124";
break;
case 9696:
credit1 = 3;
a = "COP 100";
break;
case 4580:
credit1 = 3;
a = "MAT 230";
break;
case 4581:
credit1 = 4;
a = "MAT 231";
break;
case 4582:
credit1 = 2;
a = "MAT 232";
break;
case 4583:
credit1 = 2;
a = "MAT 233";
break;
case 3587:
credit1 = 4;
a = "MAT 256";
break;
case 4519:
credit1 = 3;
a = "COP 420";
break;
case 6997:
credit1 = 1;
a = "GOL 127";
break;
case 9494:
credit1 = 3;
a = "COP 101";
break;
default:
printf("Sorry invalid entry!\n\n");
}
printf("%.2d\t%.2c\t%.2f\t\t$ %.2f\n", course, a, credit1 , credit1*120.25);
}
int main()
{
/*taking in the variables amounts*/
printf("Please enter Student ID:\n");
scanf("%i", &studentId);
printf("Enter how may courses-up to 3:\n");
scanf("%f", &amount);
for(i = 1; i = amount; i++){
printf("Enter the %.2f course number(s)\n", amount);
scanf("%i %i %i", &course, &course1, &course2);
courseInfo(course);
courseInfo(course1);
courseInfo(course2);
}
I just wanted the input to say 3 courses for example, you would input the 3 courses CRNs you wanted to take, it would run into the function and then print out the prices and what you were taking, then repeat the loop for the next 3. I figured if nothing was input like if someone chose 1 course, the course1 and course2 variables would not be assigned a value thus skipping the switch
floatones at that. I highly recommend you default to local integer variables.%iis (almost) always wrong, you want to use%d.%iinterprets input prefixed with0xas hex and input prefixed with0as octal. And it's also quite hard to confuse them ... general"%i"nteger, but%decimal.