This is a gpa calculator....this code is working 100% but if i use for example course1=getchar(); and so on with the rest of the courses...the prog only waits for me to input for the first course while it skips the other courses...in addition to that the getchar() which makes the program not end if i just open the EXE file and not from the cmd it doesnt make any difference although it did with me when i wrote other progs.thanks
Code:
#include<stdio.h>
void switcher(float *x){
if(*x>=90.0)
*x=12.0;
else if(*x>=85.0)
*x=11.0;
else if(*x>=80.0)
*x=10.0;
else if(*x>=75.0)
*x=9.0;
else if(*x>=70.0)
*x=8.0;
else if(*x>=65.0)
*x=7.0;
else if(*x>=60.0)
*x=6.0;
else if(*x>=55.0)
*x=5.0;
}
#define max 4
main(){
float *p1,*p2,*p3,*p4,*p5,*p6,course[6];/*i made a pointer to each course so that in order to make the reference call*/
int i;
float sum,totalgpa;
float gpa[max]={3.94,2.88,3.83};/*i initiated the first 3 elements because these are the past semesters*/
printf("\nHello Amr\n");
printf("\nMaths 4 : ");
scanf("%f",&course[0]);
printf("\nDigital Logic Design : ");
scanf("%f",&course[1]);
printf("\nElectronic Devices 1 : ");
scanf("%f",&course[2]);
printf("\nElectrical Circuits 2 : ");
scanf("%f",&course[3]);
printf("\nMeasurements : ");
scanf("%f",&course[4]);
printf("\nScientific Thinking : ");
scanf("%f",&course[5]);
p1=course;
p2=&course[1];
p3=&course[2];
p4=&course[3];
p5=&course[4];
p6=&course[5];
switcher(p1);
switcher(p2);
switcher(p3);
switcher(p4);
switcher(p5);
switcher(p6);
sum=0.0;
for(i=0;i<6;i++)
sum+=course[i];
gpa[max-1]=sum/18;
sum=0.0;
for(i=0;i<max;i++)
sum+=gpa[i];
totalgpa=sum/4;
printf("\nThe term's GPA is %1.2lf\n", gpa[max-1]);
printf("\nTotal GPA is %1.2lf\n", totalgpa);
}