General discussion

Locked

C Programming Help

By ssaintgeorge ·
I have an assignment to complete in the next 5 hours and can't figure out how to make it work. Below is the code for what does work. The assignment asks for the user to enter as many grades as they would like (need to keep track of how many grades user enters)and print the average grade. I am having difficulty with this. I've been known to make this more difficult than it is which is probably the case now.

#include <stdio.h>
main()
{

int num1,num2,num3,average,total;
int x=0;
int y=0;
int z=0;
int choice;
int a=1;

while(a==1)
{

printf("Enter first grade between 60 and 100\n");
scanf("%d",&num1);
printf("Enter second grade between 60 and 100\n");
scanf("%d",&num2);
printf("Enter third grade between 60 and 100\n");
scanf("%d",&num3);

switch (choice)
{
case 1:
x++;
break;
case 2:
y++;
break;
case 3:
z++;
break;
default: printf("You made a wrong choice\n");
}
printf("would you like to continue? 1 for yes, 2 for no\n");
scanf("%d",&a);
}
total=num1+num2+num3;

printf("the total of all grades is: %d\n",total);
average=total/3;
printf("Your average grade is: %d\n",average);
if(average>75)
printf("You pass\n");
else if(average<75)
printf("You need more work\n");

getchar();

}

Thanks,

Steve

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Back to Peripheral Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums