I am new to C programming and we are still starting with loops. For our exercises, today we were instructed to create a do-while program that calculates how many passed and unsuccessful grades are, but the cycle is interrupted when a negative number is entered. In addition, numbers above 100 are skipped. This is my program:
#include<stdio.h> #include<conio.h> int main() { int grade, pass, fail; pass = 0; fail = 0; do { printf("Enter grade:\n"); scanf("%d", &grade); printf("Enter -1 to end loop"); } while(grade == -1){ if(grade < 100){ if(grade >= 50){ pass = pass + 1; } else if { fail = fail + 1; } } break; } printf("Pass: %d", pass); printf("Fail: %d", fail); getch (); return 0; }
Can someone please tell me how to improve or where did I go wrong?
source share