Code:
#include<stdio.h>
// Function main begins program execution
int main(void)
{
// intialize variable in definitions
unsigned int passes = 0; // number of passes
unsigned int failures = 0; // number of failures
unsigned int student = 1; // student counter
int result, temp; // one exam result
// process 10 students using counter-controlled loop
while(student <= 10) {
// prompt user for input and obtain value from user
printf("%s", "Enter result(1=pass, 2=fail):");
scanf("%d", &result);
if(result<1){
printf("Invalid input...please enter a 1 or 2\n");
scanf("%d", &result);
}
if(result>2){
printf("invalid input...please enter a 1 or 2\n");
scanf("%d", &result);
}
if(result=0){
printf("invalid input...please enter a 1 or 2\n");
scanf("%d", &result);
}
// if result 1, increment passes
if (result ==1) {
passes = passes + 1;
}// end if
else { // otherwise, increment failures
failures = failures + 1;
} // end else
student = student + 1; // increment student counter
}// end while
// termination phase; display number of passes and failures
printf("Passed %u\n", passes );
pr
// if more than eight passed, print "Bonus to instructor!"
if (passes > 8) {
puts("Bonus to instructor!");
} // end if
} // end function main
intf("Failed %u\n", failures );
when i do it this way it say invalid input but then it goes directly to the EOF
is there a simple one line while loop that i can use.
I'm just trying to make sure the user can only put in a 1 or 2
thanks to all in advance