Write a loop using a sentinel value. The sentinel value will be \"999\" and when
ID: 3653832 • Letter: W
Question
Write a loop using a sentinel value. The sentinel value will be "999" and when this number is entered, the loop will end. The user will enter a number. You will examine the number and determine if it is even or odd. If it is even, you will add one to the even counter. If it is odd, add one to the odd counter. When the loop has ended, print out a message telling how many even and odd numbers were entered.Explanation / Answer
int main() { int i; float num, even, odd; i = 0; while (i >=1); num++; printf("Enter a number (999 to exit): "); scanf("%f", &num); if (num==999){ printf("You have entered %d even numbers ",even); printf("You have entered %d odd numbers " ,odd); break; } if(num==2){ even += 1; } else{ odd += 1; } system("PAUSE"); }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.