im a newbie at c please help.
Please could someone explain to me why this isnt working, also is there a way for me to not have to type in all the variables when i want multiple typed like i have done here. thanks.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(){
int grade[10][0];
grade[0][0]=0;
grade[1][0]=0;
grade[2][0]=0;
grade[3][0]=0;
grade[4][0]=0;
grade[5][0]=0;
grade[6][0]=0;
grade[7][0]=0;
grade[8][0]=0;
grade[9][0]=0;
printf("Please enter your students exam mark seperated by a space \n");
fflush(stdin);
scanf("%d %d %d %d %d %d %d %d %d %d \n", grade[1][0], grade[2][0], grade[3][0],grade[4][0], grade[5][0], grade[6][0], grade[7][0], grade[8][0], grade[9][0], grade[0][0]);
float totgrade= grade[1][0]+grade[2][0]+grade[3][0]+grade[4][0]+grade[5][0]+grade[6][0]+grade[7][0]+grade[8][0]+grade[9][0]+grade[10][0];
printf("The total mark is: %f \n", totgrade);
float avgrade=totgrade/10;
printf("The average mark = %.1f", avgrade);
system("pause");
return 0;
}
Ive got to this but it still crashes after i input the 10 numbers.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(){
int grade[10]={0};
printf("Please enter your students exam mark seperated by a space \n");
scanf("%d %d %d %d %d %d %d %d %d %d \n", grade[1], grade[2], grade[3],grade[4], grade[5], grade[6], grade[7], grade[8], grade[9], grade[0]);
printf("%d", grade[4]);
float totgrade= grade[1]+grade[2]+grade[3]+grade[4]+grade[5]+grade[6]+grade[7]+grade[8]+grade[9]+grade[0];
printf("The total mark is: %f \n", totgrade);
float avgrade=totgrade/10;
printf("The average mark = %.1f", avgrade);
system("pause");
return 0;
}