Question

C++ assignment Write a program that reads a sequence of integers and prints the following: 1....

C++ assignment

Write a program that reads a sequence of integers and prints the following:

1. The number of odd and even numbers of inputs Use a sentinel value to signal the end of inputs.

If the sentinel value is the first you enter, give a message “NO input is entered!”. Input Validation: Do not accept a negative number.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int main()
{
   int n;
   cout<<"Enter number: ";
   cin>>n;
   if(n==0){
      cout<<"NO input is entered!";
   }
   else{
      int oddCount = 0, evenCount = 0;
      while(n!=0){
         if(n>0){
             if(n%2==0){
                evenCount++;
             }
             else{
                oddCount++;
             }
         }
         cout<<"Enter number: ";
         cin>>n;
      }
      cout<<"Even count = "<<evenCount<<endl;
      cout<<"Odd count = "<<oddCount<<endl;  
   }
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ assignment Write a program that reads a sequence of integers and prints the following: 1....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT