Question

In: Computer Science

Write a C++ code that keeps reading integer numbers (x) until a negative number is entered....

Write a C++ code that keeps reading integer numbers (x) until a negative number is entered. Every time x is entered, the program does the following: calculates and prints the product of odd numbers. calculates and prints the count of numbers that ends with 19. Example, 19, 3219, 50619,....etc calculates and prints the percentage of the numbers that contain 3 digits exactly, such as, 301, 500, 206,...etc.

Solutions

Expert Solution

Code :

#include <iostream>
using namespace std;

int main()
{
int n;
int c=0; // counter to count no of integres inputted by iser
int end19=0; // counter to count no of integers that ends with 19
int digits3=0; // counter to count no of integers that contains 3 digits
int prod=1; // varaible to calculate product of odd numbers

while (1)
{
cout << "Enter an integer: ";
cin >> n;
cout << n<<"\n";
c=c+1;
if ( n <0) // If no id negative then we will come out of loop
break ;
if (n%2!=0) // If the no is odd
prod=prod*n; // It will calculate the product
if (n > 99 && n <1000) // If the no has exactly 3 digits
++digits3 ; // It will increment the counter digits3
if (n%100 ==19) // If the number ends with 19
++end19; // It will increment the counter end19
  
cout << "Product of odd integere: " << prod <<"\n";
cout <<"percentage of numbers that ends with 19: "<< (end19*100.0)/c <<"%\n";
cout <<"percentage of numbers that contains 3 digits: "<< (digits3*100.0)/c <<"%\n";
  
}

return 0;
}

I am adding the screenshot of some outputs:

Output 2:


Related Solutions

Write a C++ program that keeps asking user to enter a positive integer number until a...
Write a C++ program that keeps asking user to enter a positive integer number until a sentinel value (999) is entered. Then for each positive number entered by the user, find out how many digits it consists. (Hint: divide a number by 10 will remove one digit from the number. You can count how many divisions it needs to bring the number to 0.) An example of executing such a program is shown below. Note that the user input is...
Write a C++ program that randomly generates N integer numbers (such that N is entered by...
Write a C++ program that randomly generates N integer numbers (such that N is entered by the user) and then stores them to a text file (myNumbers.txt) sorted in increasing (non-decreasing) order. Again, please notice that the size of the data (N) is known during the run time, not the compile-time (needs to be entered by the user after running the program).
"PYTHON" Write some code " USING PYTHON" to keep reading numbers from the user until the...
"PYTHON" Write some code " USING PYTHON" to keep reading numbers from the user until the users enters a negative number. The program then prints out: a) the sum of all the numbers b) the average of all the numbers c) the max of the numbers d) the min of the numbers Note we did not cover lists (array) so you will not use them in this problem. Finally, ask the user for their name, then print their name as...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking integers until the user enters -100. In the end, the program should display the count of positive, negative (excluding that -100) and zeros entered. Sample Input/Output 1: Input the number: 0 2 3 -9 -6 -4 -100 Number of positive numbers: 2 Number of Negative numbers: 3 Number of Zero: 1
a) Write C code using a struct to hold student information: integer id integer number of...
a) Write C code using a struct to hold student information: integer id integer number of hours taken integer number of hours passed double gpa b) create a variable of the type in #25 and initialize it with some data.
Write a C++ program to read a collective of integer numbers. I f the number is...
Write a C++ program to read a collective of integer numbers. I f the number is greater than zero and less than 15 then terminate the loop and find factorial of the number
Write a C code program to implement the comparisons of three integer numbers, using only conditional...
Write a C code program to implement the comparisons of three integer numbers, using only conditional operators (no if statements). Please ask the user to input random three integers. Then display the minimum, middle, and maximum number in one line. Also, please calculate and display the sum and the average value (save two digits after decimal point) of these three integers. Please write the comments line by line.
Python Jupiter Notebook Write a program that keeps getting a set of numbers from user until...
Python Jupiter Notebook Write a program that keeps getting a set of numbers from user until the user enters "done". Then shows the count, total, and average of the entered numbers. Example: Enter a number: 55 Enter a number: 90 Enter a number: 12 Enter a number: done You entered 3 numbers, total is 157, average is 52.33333
Write a program that reads n integer values. If a negative value is entered, we want...
Write a program that reads n integer values. If a negative value is entered, we want to terminate the input, i.e., exit from the loop. If a zero value is entered, we want to ignore it and read the next value. Any strictly positive values (greater or equal zero) are to be totaled. Print the number of values read, the number of values totaled and the total. If a negative value is entered, print an error message before terminating the...
Let a , b , c be three integer numbers. Write a C++ program with a...
Let a , b , c be three integer numbers. Write a C++ program with a functions void rotate1(int* a,int* b,int* c) void rotate2(int& a,int& b,int& c) such that a -> b , b -> c and c -> a. Thus we use two different approaches (pointers in rotate1 and references in rotate2).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT