Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trouble Retuning to Previous input in loop

I am creating a program that will have me enter 6 grades 1-50 and have it give me the total amount of points and the percentage of the scores. The only trouble I am having on it is that when the if loop activates, it will not return to the previous input and will skip to the next input. How do I make it so that it returns to the previous input so that it can be re entered?

#include <stdio.h>
int main() {
      int percent;
      int totalscore;
      const int score[5];
   for (int grades = 1; grades <= 6; grades++) { 
         printf("please enter the grade for assignment #%d: ", grades);
         scanf("%d", &score[grades]);
   if (score > 0 , score > 51);
      printf("Please enter a number between 1 and 50\n");
      
   }
   totalscore = score[1] + score[2] + score[3] + score[4] + score[5] + score[6];
   printf("Over 6 assignments you earned %d points out of a possible 300 points!\n", totalscore); 
percent = totalscore / 3 ;
   printf("Your grade is %d percent.", percent);
   return 0;
   }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In this code, you are making two mistakes. The first is you are using a semicolon ‘;’ at the end of the ‘if’ statement, and the second is that you have used ‘,’ in the ‘if’ condition, which is not right.
You can see the correction below:-

if (score <= 0 || score >= 51)
    printf("Please enter a number between 1 and 50\n");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading