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

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

  • Write a C program to sum up all the odd numbers between a lower limit number...

    Write a C program to sum up all the odd numbers between a lower limit number and an upper limit number provided by a user. The requirements are: First, request the user to provide a lower limit integer number and an upper limit integer number that is larger than the lower limit number, and save them in variables lowerLimit and upperLimit, respectively. If the user has entered an upper limit number (upper Limit) that is NOT larger than the lower...

  • JAVA - the program should output as follows: Please enter a seed: 2345 Please enter the...

    JAVA - the program should output as follows: Please enter a seed: 2345 Please enter the size of the array: 1 Array size must be greater than 1. Please reenter: 0 Array size must be greater than 1. Please reenter: -1 Array size must be greater than 1. Please reenter: 8 Please choose an option: 1 Print the array 2 Find the average 3 Find the largest element 4 Count how many times 3 occurred 5 Count how many elements...

  • In Python Language: Design a program that generates 300 random numbers, and keeps a count of...

    In Python Language: Design a program that generates 300 random numbers, and keeps a count of how many of those random numbers are even and how many are odd. Note: If possible please include screenshot of code to study

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

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