Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include using namespace std;

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>gradesCh[i];

}

cout<<"Enter hours for each course : "<>hours[i]; }

gpa = Gpa(gradesCh, hours, num);

} else { float *grades = (float*)malloc(num*sizeof(float)); for(i=0; i>grades[i]; }

cout<<"Enter hours for each course : "<>hours[i]; }

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Write the difference between sexual and asexual reproduction.

Answered: 1 week ago

Question

What your favourite topic in mathematics?

Answered: 1 week ago

Question

Briefly describe vegetative reproduction in plants.

Answered: 1 week ago

Question

7. Senior management supports the career system.

Answered: 1 week ago