Question

Write a c++ complete program to meet the specifications. The program should prompt the user for...

Write a c++ complete program to meet the specifications.

The program should prompt the user for a positive integer.

The program should print a message whether the integer is even or odd.

The looping should end when the user enters a negative number.

The negative number will not be tested for even or odd.

The program will print out a message of how many numbers were entered (not counting the negative number) and how many even and odd numbers were entered. Make sure to indent where needed. A sample program run (user input is in bold): Welcome to Integer Test! Please enter an integer: 44 44 is even. Please enter an integer: 42 42 is even. Please enter an integer: 77 77 is odd. Please enter an integer: 0 0 is even. Please enter an integer: -5 You tested 4 integers! Number of even integers: 3 Number of odd integers: 1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Code for Above problem:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    cout<<"Welcome to Test!"<<endl;
    bool loop=true;
    int value;
    int tested=0;
    int even_count=0;
    int odd_count=0;
    while(loop)
    {
        cout<<"Please Enter an Integer: ";
        std::cin >> value;
        if(value<0)
        {
            loop=false;
        }
        else if(value%2==0)
        {
            cout<<value<<" is Even" <<endl;
            even_count=even_count+1;
            tested=tested+1;
        }
        else
        {
            cout<<value<<" is Odd" <<endl;
            odd_count=odd_count+1;
            tested=tested+1;
        }
      
    }
    cout<<"You tested "<<tested<<" Integers!"<<endl;
    cout<<"Number of even integers: "<<even_count<<endl;
    cout<<"Number of odd integers: "<<odd_count<<endl;

    return 0;
}


OUTPUT OF ABOVE CODE:

Welcome to Test                                                                                                                 

Please Enter an Integer: 44                                                                                                     

44 is Even                                                                                                                      

Please Enter an Integer: 42                                                                                                     

42 is Even                                                                                                                      

Please Enter an Integer: 77                                                                                                     

77 is Odd                                                                                                                       

Please Enter an Integer: 0                                                                                                      

0 is Even                                                                                                                       

Please Enter an Integer: -5                                                                                                     

You tested 4 Integers!                                                                                                          

Number of even integers: 3                                                                                                      

Number of odd integers: 1    

Add a comment
Know the answer?
Add Answer to:
Write a c++ complete program to meet the specifications. The program should prompt the user for...
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
  • Write a Java program to prompt for inputting an integer N, then enter N integers (a...

    Write a Java program to prompt for inputting an integer N, then enter N integers (a loop is needed), print the numbers user entered, and the amount of even and odd numbers (zero is even number). (1) Prompt for the user to input an integer and output the integer. (1 pts) Enter an integer: You entered: 5 (2) Prompt for the user to input N integers, output the numbers entered and the amount of even and odd numbers (9 pts)...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • In this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

  • Write a program that prompts the user for positive integers, only stopping when a negative integer...

    Write a program that prompts the user for positive integers, only stopping when a negative integer or zero is given. The program should then print out how many of the positive integers were odd. Example: Enter a positive integer (0 or negative to stop): 9 Enter a positive integer (0 or negative to stop): 4 Enter a positive integer (0 or negative to stop): 7 Enter a positive integer (0 or negative to stop): -3 You entered 2 odd integers....

  • Write a Java program that: • Asks the user to enter the number of integers that...

    Write a Java program that: • Asks the user to enter the number of integers that he need to enter; • Asked him to enter integer by integer; • Print The number of Odd numbers entered and the number of Even numbers entered. Important notes: 1. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable. 2. Take a screen shot for your...

  • How to write this code in C++???? using fstream Write a program which: Asks the user...

    How to write this code in C++???? using fstream Write a program which: Asks the user to enter a positive integer greater than 0 Validates that the entry is a positive integer Outputs the digits in reverse order with a space separating the digits Outputs the even digits not in reverse order with a space separating the digits (consider zero to be even) If there are no even digits, the an appropriate message should be displayed: There are no even...

  • Program C: Start by printing out your name, then your code should prompt the user to...

    Program C: Start by printing out your name, then your code should prompt the user to enter integers using the following prompt: Enter some integers, end with a 0: Your code should: Level 1 Task: count the number of integers entered (not including the 0) Level 2 Task: produce the sum of all of the integers Level 3 Task: produce the sum of the even integers These calculated values need to be displayed as follows: There were ___ numbers read...

  • Write code to repeatedly ask the user for a number. If the number is positive and...

    Write code to repeatedly ask the user for a number. If the number is positive and even, print out a happy message. If the number is positive and odd, print out a sad message. If the number is negative, print out an angry message If they enter zero, stop asking If they enter something that isn't an integer, print out a message telling them they are an idiot, but keep looping

  • C++ please no arrays! Create a program that will allow the user to enter up to...

    C++ please no arrays! Create a program that will allow the user to enter up to 50 whole values and determine the number of values entered, how many of the values were odd and how many of the values were even. Your code should contain 2 functions, a main function and a function to enter the numbers enter and count the values. Your main function should be a driver program that will call another function to count the total number...

  • use C++ please 1. Vowels and Consonants Write a program that asks the user to input...

    use C++ please 1. Vowels and Consonants Write a program that asks the user to input three different integers. Write a function called numberStyle for this program that will accept each integer (one at a time) and return the following . If the integer is even, return 1 . If the integer is odd, return -1 . If the integer is zero, return O In main, after calling the function output the appropriate message describing the integers ing the function...

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