New in c can someone help??

+1 Rodrigo Lopes · February 9, 2016
Hi everyone, so i made a program which should calculate the average of your tests. however the average keeps the same! can someone help me out please? ty anyway^^


#include <stdio.h>
#include <stdlib.h>

int main()
{
float notesadded = 0;
float average = 0;
float numberOftests = 0;
float scoreentered = 0;
char grade[50];

printf("Hi this program will help you calculating your tests average!\n\a");
printf("Whenever you want to quit the program just enter 0\n");

do{
printf("In %.2f tests your average is %.2f\n", &numberOftests, &average);
printf("Enter now you new grade\n");

scanf("%f", &scoreentered);
notesadded += scoreentered;
numberOftests++;
average = notesadded / numberOftests;

if(average >= 90){
printf("Your grade is:Excellent\n");
}else if(average > 80){
printf("Your grade is:Normal\n");
}else{
printf("Your grade is:Bad\n");
}


}while(scoreentered !=0);

Post a Reply

Replies

Oldest  Newest  Rating
0 kuldeep kanzariya · February 16, 2016
#include <stdio.h>
#include <stdlib.h>

int main()
{
float notesadded = 0;
float average = 0;
float numberOftests = 0;
float scoreentered = 0;

printf("Hi this program will help you calculating your tests average!\n\a");
printf("Whenever you want to quit the program just enter 0\n");

do{
//U should decide how many Tests are there,it should be pre-defined OR User defined.
// if it is user defined then ask user to enter Numbers of tests only ONCE......!!!
// Dont Take Useless Variables
printf("In %.2f tests your average is %.2f\n", &numberOftests, &average); 
printf("Enter now you new grade\n");

scanf("%f", &scoreentered);
notesadded += scoreentered;
numberOftests++;
average = notesadded / numberOftests;

if(average >= 90){
printf("Your grade is:Excellent\n");
}else if(average > 80){
printf("Your grade is:Normal\n");
}else{
printf("Your grade is:Bad\n");
}


}while(scoreentered !=0);
0 Linguist Llama · February 9, 2016
Is your compiler showing you any warnings? It should be... and you should be reading them and trying to understand what they're saying... Here's what my compiler says when I try to compile your code:

C:\Users\Seb\Desktop>gcc -Wall -pedantic code.c
code.c: In function 'main':
code.c:16:8: warning: format '%f' expects argument of type 'double', but argument 2 has type 'float *' [-Wformat=]
printf("In %.2f tests your average is %.2f\n", &numberOftests, &average);
code.c:16:8: warning: format '%f' expects argument of type 'double', but argument 3 has type 'float *' [-Wformat=]
code.c:10:6: warning: unused variable 'grade' [-Wunused-variable]
char grade[50];


Do you have any questions about these warnings?
  • 1

C

106,943 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator