hello everyone
ı have a problem with writing the program

#include <stdio.h>


int main(void)
{

     char desiredgrade;  double score;
     double currentaverage; 
    double weight; 

printf("Enter your desired grade");
scanf("%c,&desiredgrade");
printf("Enter your current average in the course");
scanf("%f,&currentaverage");
printf("Enter the final exam weight\n");
printf("as a percentage of the course grade");
scanf("%lf,&weight");




 if ( 90<=desiredgrade && desiredgrade<=100)
      { 
          score =(desiredgrade-(currentaverage*(100-weight)/100)+(100/weight));
          printf("You need a score of %.2f on the final to get A\n",score);
      }
      else if (80<=desiredgrade && desiredgrade<=90)
      {
          score=(desiredgrade-(currentaverage*(100-weight)/100)+(100/weight));
          printf("You need a score of %.2f on the final to get B\n",score);
      }
      else if (70<=desiredgrade && desiredgrade<=80)
      {
          score=(desiredgrade-(currentaverage*(100-weight)/100)+(100/weight));
          printf("You need a score of %.2f on the final to get C\n",score);
      }
      else if (60<=desiredgrade && desiredgrade<=70)
      {
          score=(desiredgrade-(currentaverage*(100-weight)/100)+(100/weight));
          printf("You need a score of %.2f on the final to get D\n",score);
      }
          return 0 ;
      }

ı wrote the program like that but program give me 3 warning which are;

warning C4700: local variable 'desiredgrade' used without having been initialized
: warning C4700: local variable 'weight' used without having been initialized
: warning C4700: local variable 'currentaverage' used without having been initialized

please help me
ı had to wirite a program that predicts the score needed on a final exam to achieve a desired grade in a course

Recommended Answers

All 4 Replies

Just try to modify the first part (var declarations) like this:

char desiredgrade=NULL;
double score=0.0;
double currentaverage=0.0;
double weight=0.0;

Compiler is warning you that you have'nt perform initializiation (memory allocation)for those variabils:

your begining code:

printf("Enter your desired grade");
scanf("%c,&desiredgrade");

dose not TELL compiler to allocate memory, ---> WARNING

printf("Enter your desired grade");
scanf("%c,&desiredgrade");
printf("Enter your current average in the course");
scanf("%f,&currentaverage");
printf("Enter the final exam weight\n");
printf("as a percentage of the course grade");
scanf("%lf,&weight");

Note the position of the closing quotes. And pay attention to the format specifiers.

printf("Enter your desired grade");
 scanf("%c",&desiredgrade);
 printf("Enter your current average in the course");
 scanf("%lf",&currentaverage);
 printf("Enter the final exam weight\n");
 printf("as a percentage of the course grade");
 scanf("%lf",&weight);

When you are just starting, using scanf you are almost guaranteed to have issues. Try this to get around the "it skips the next input" issue.

scanf("%c%*c",&desiredgrade);
char desiredgrade=NULL;

NULL is meant for pointers, not characters. Perhaps you meant '\0' or simply 0.

Yes .... that is correct!!! NULL is meant for pointers;
In this case, using NULL instead of '\0' works, but it is NOT correct. Thanks for remembering this aspect.

I've not notice the quotes mistakes: Another lesson: Pay more attention when reading; Thanks again. :)

Still neccessary to, to me, to make initialization when declaring a variable to avoid warnings.

Is it possible to make a prediction programm, because then the computer has to travel in time(the future) to get information and get back right, how can a single computer do that without sattelites and signals, do you use a special clock or what?

Can you answer me please, lets say i want to predict something that is gonna happen 2 houres from now,

example on subject: the score result that is gonna come 2 houres from now.

How can a single program make this work, Now i just want to know if it is possible dont need the codes. Yes or no

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.