moded
Code:
$ ./a.out
$ ./a.out
Enter the grades. Enter -1 to stop.
70
0 = 547313808 + 1
1 passingG 0, failingG 0
2 passingG 0, failingG 0
Floating point exception
userx@slackwhere:~/bin
you code
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int grades, passingGrades, total, failingGrades;
double percentage;
passingGrades = 0; // stays 0 no assinging it anything after you
failingGrades = 0; // stays 0 get input from grades.
while(grades != -1)
{
// Ask the user to input grades, and type -1 to stop
printf("Enter the grades. Enter -1 to stop. \n");
scanf("%d", &grades);
// If the user enters anything lower than -1 or higher than 100, code displays an error.
if(grades > 100 || grades < -1)
{
printf("That is not a valid grade. \n");
}
{ //opens here -
if (grades == -1)
{
grades = -1;
}
else if (grades <= 100 && grades >= 70.0)
{
// Calculates the number of passing grades
printf("%i = %i + 1 \n", passingGrades);
printf("1 passingG %d, failingG %d\n", passingGrades, failingGrades);
total = passingGrades + failingGrades;
printf("2 passingG %d, failingG %d\n", passingGrades, failingGrades);
//stays (0/0) * 100
percentage = (passingGrades / total) * 100;
}
else
{
grades = 0;
// Calculates the total and percentage
}
} // closes here :: what need is theses brackets?
} // end while
// Prints results to user
printf("passingG %d, percentage %.2lf\n", passingGrades,percentage);
printf("%i are passing grades. \n", passingGrades);
printf("%.2lf percent are passing grades. \n", percentage);
// Need to fix percentage calculation...
system("pause");
}