Originally Posted by
davidjg
Here is the code I have wrote along with output results and complier errors. Can someone please offer this programming newb some guidance? Thanks!
You'll probably get better suggestions from some of the others but I've noted a couple of things in red that may help you along....
Code:
#include <stdio.h>
int main()
{
int x, y, z;
//x is the Grade Average <--- use descriptive names eg: int NumGrades
//y is the total grade
//z is the number of grades
float gradeAverage(int, int); <<--- these should be above main, not in main
char printgrade(float);
printf("Enter the number of grades: %d\n", z);
scanf("%d", z); <---- should be scanf("%d",&z);
for(z=0;z<5;z++) <---- should be: for (int i = 0; i < z; i++);
{
printf("The ", z); <--- s/b printf("The %d", i);
printf("grade is \n");
scanf("Please enter the grade %d\n", &z); <--- should be at the top of the loop
}
return 0;
}
float x(int y, int z)
{
int total;
float avg;
avg = total/y;
return avg; <---- exit before printing result
printf("The grade average is: %d\n");
}
//char printgrade(float y);
//{
// if(y>=90)
// return 'A';
// printf("You got A for the cource\n");
//else
//if(y>=80)
//return 'B';
//printf("You got a B for the cource\n");
//else
//if(y>=70)
//return 'B';
//printf("You got a C for the cource\n");
//else
//if(y>=60)
//return 'C';
//printf("You got a D for the cource\n");
//else
//if(y>=50)
//return 'F';
//printf("You got an F for the cource\n");
//}
Think about the order in which things have to be done. Think about doing it in the minimum number of steps.
Also as a matter of personal style... I use function declarations (the ones with the semicolons) very sparingly. I prefer to put my main() at the bottom of the page and place functions above. I find it very helpful in finding problems with undeclared or unintialized variables.