Question
Can somebody fix this code I get a runtime error Run-Time Check Failure #3 - The variable 'num' is being used without being initialized #include
Can somebody fix this code I get a runtime error Run-Time Check Failure #3 - The variable 'num' is being used without being initialized
#include
float GradePoints(char grade) //To convert Grade to grade points { float p; switch(grade) { case 'A' : p= 4.0; break; case 'B': p= 3.0; break; case 'C': p= 2.0; break; case 'D': p= 1.0; break; case 'F': p= 0.0; break;
} return p;
}
float Gpa(const char grade[], const int hours[], int arrlength) //To calculate GPA for grades in character array { int i, sum_hrs=0; float sum_gp = 0, p;
for(i=0; i sum_hrs += hours[i]; } return sum_gp/sum_hrs; } float Gpa(const float gradePoints[], const int hours[], int arrlength) //To calculate GPA for grade in points { int i, sum_hrs=0; float sum_gp = 0; for(i=0; i sum_gp += gradePoints[i]*hours[i]; sum_hrs += hours[i]; } return sum_gp/sum_hrs; } int main() //Main function { int num, i, sum=0, choice; float gpa; int *hours = (int*)malloc(num*sizeof(int)); cout<<"Enter number of courses : "; cin>>num; cout<<"Enter Grade for each course. Enter 1 to enter Grades or 2 to enter grade points :"; cin>>choice; if(choice == 1) { char *gradesCh = (char*)malloc(num*sizeof(char)); for(i=0; i } cout<<"Enter hours for each course : "< gpa = Gpa(gradesCh, hours, num); } else { float *grades = (float*)malloc(num*sizeof(float)); for(i=0; i cout<<"Enter hours for each course : "< gpa = Gpa(grades, hours, num); } //printf("%f", GradePoints('C')); cout<<"Result : "<< gpa; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started