Question

this is for a c++ program Ask the users for numbers until the total of the...

this is for a c++ program Ask the users for numbers until the total of the numbers is greater than 30. Also, count how many numbers are even and how many are odd. Total is 0 Please enter an integer: 20 Total is 20 Please enter an integer: 7 Total is 27 Please enter an integer: 2 Total is 29 Please enter an integer: 1 Total is 30 Please enter an integer: 1 You had 2 even numbers and 3 odd numbers.

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

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new C++ program with name "main.cpp" is created, which contains following code.

main.cpp :


#include <iostream>
using namespace std;
int main()
{
int total=0;//variable to store sum
int evenCount=0;//variable to store even numbers count
int oddCount=0;//variable to store odd numbers count
int number;//variable to store number
//using while loop
while(total<30)
{
//asking user to enter number
cout<<"Please enter an integer:";
cin>>number;//reading number
total=total+number;//adding number in total
//checking for even and odd number
if(number%2==0)
{
evenCount++;//count number as even
}
else
{
oddCount++;//count number as odd
}
//display total
cout<<"Total is "<<total<<endl;
  
}
//print even and odd number count
cout<<"You had "<<evenCount<<" even numbers and "<<oddCount<<" odd numbers.";
return 0;
}

======================================================

Output : Compile and Run above program to get the screen as shown below

Screen 1 :main.cpp

input Please enter an integer:20 Total is 20 Please enter an integer:7 Total is 27 Please enter an integer:2 Total is 29 Plea

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
this is for a c++ program Ask the users for numbers until the total of the...
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 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...

  • 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...

  • using c++ write a program that reads numbers from the user until the user enters a...

    using c++ write a program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following:   must use loops and numbers to do this 1. Output the sum of all even numbers 2. Output the sum of all odd numbers 3. Output the count of all even numbers 4. Output the count of all odd numbers

  • This MUST be done in C++ Write a program with a loop to ask the user...

    This MUST be done in C++ Write a program with a loop to ask the user for an integer greater than or equal to 2 and then pass the integer to a function which will produce and display on the console the ulam sequence1. Do not accept a number less than 2. 1The ulam sequence begins with an integer. If it is even, divide by 2. If it is odd, multiply by 3 and add 1. Then apply the appropriate...

  • 1. Write a program to add positive numbers. Ask the user to enter numbers greater than...

    1. Write a program to add positive numbers. Ask the user to enter numbers greater than zero. If a 0, is entered stop requesting numbers and display the total. If a number is entered that is less than 0, display the message ‘Number must be greater than 0’, then ask for another number to be entered. Repeat until a number greater than 0 or 0 is entered. use math lab so I can copy the answers

  • please solve in c++ MULT PLES number Writo a complete nat counts and prints the even...

    please solve in c++ MULT PLES number Writo a complete nat counts and prints the even pies of 5 as well as the number of multiples of 8 be.ween two integer values entered by the user and the total number. You must use a while or do ... while loop. If the user's first input is greater than or equal to the second one, your program should ask the user for another two inputs until the first one is less...

  • python la ab X, X Lab 7 Design and implement a Python program that uses a...

    python la ab X, X Lab 7 Design and implement a Python program that uses a while loop and selection statements to print the sum of the even numbers and the sum of the odd numbers (all integers) read from the keyboard. The sequence of numbers ends with a negative number: So, all numbers considered for printing the two sums are greater than or equal to 0. The sequence may be empty. Here is a possible interaction. Enter an integer:...

  • Write a java program that keeps asking the user to enter a number until the user...

    Write a java program that keeps asking the user to enter a number until the user quits and prints how many even and how many odd numbers entered by the user. The loop terminates if the user enters -1 (it indicates that there will be no more number entering by the user). In other words, as long as the user doesn’t enter -1, the loop will be executed. Please add comments to the program to understand/ explain the code.

  • 30. Create a program that will create a "number battle" between two users. Ask each user to enter three numbers that sum to a maximum of 30. Then the program will compare each users 1st, 2nd...

    30. Create a program that will create a "number battle" between two users. Ask each user to enter three numbers that sum to a maximum of 30. Then the program will compare each users 1st, 2nd and 3rd number and determine who won each battle. For instance if user A enters 18,11,1 and user B enters 6,17,7 then user B would win because they won 2 of 3 battles. Have a check to see if the sum to 30 rule...

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

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