Question
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 prime if it is even and 2. If a number is odd, it is prime if it is not divisible by any odd integer less than or equal to the square root of the number. What header file will you need include to use the sqrt() function?)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

[1]

#include <iostream>
using namespace std;

int main(){
int input,sum = 0,max,min,counter=1;
float average = 0.0;
  
cout << "Enter integers : " ;
cin>>input;
cout <<input<<endl;
  
max = input;
min = input;
  
while(input != -1){
sum = sum + input;  
  
if(min > input){
min = input;
}
  
if(max < input){
max = input;
}

cout << "Enter integers : " ;
cin>>input;
cout <<input<<endl;
counter = counter + 1;
}
  


average=sum/(counter -1);
  
cout << "Min Value" << " is " << min << endl;
cout << "Max Value " << " is " << max << endl;
cout << "The sum of " << " is " << sum << endl;
cout << "The average of " << " is " << average << endl;
}

27 cin>input; cout <<input<<endl; counter-counter1; 29 34 average-sum/(counter -1); 37 38 39 40 cout << Min Value << is << min << endl; cout <<Max Value << is << max < endl; cout << The sum of <<is << sum << endl; cout くく The average of << is << average << endl; CommandLine Arguments Stdin Inputs... O Execute Save My Projects Rece Result... CPU Time: .8e sec(s), Memory: 3248 kilobyte(s) Enter integers 1 Enter integers : 2 Enter integers:3 Enter integers : 4 Enter integers5 Enter integers : -1 Min Value is 1 Max Value is 5 The sum of is 15 The average of is 3==============================================================================

[2]

#include <iostream>
using namespace std;

int main(){
int input,i;
bool isPrime = true;
  
cout << "Enter a positive integer: ";
cin>>input;
cout <<input<<endl;
  
while(input >= 0 ){
isPrime = true;
for(i = 2; i <= input / 2; ++i)
{
if(input % i == 0)
{
isPrime = false;
break;
}
}
  
if (isPrime)
cout << "This is a prime number";
else
cout << "This is not a prime number";

cout << "\n\nEnter a positive integer: ";
cin>>input;
cout <<input<<endl;
}

}

Add a comment
Know the answer?
Add Answer to:
C++ Write a program that prompts the user to enter integers or a sentinel to stop....
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 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....

  • C++ Write a program that prompts the user to enter two positive integers: num1 and num2....

    C++ Write a program that prompts the user to enter two positive integers: num1 and num2. - Validate that num1 is less than num2 and that both numbers are positive. If any of these conditions are not met, allow the user to re-enter num1 and num2 until the input is determined valid. - For all integers from num1 through num2, print the word keyboard if the current integer is divisible by 2 and print the word mouse if the current...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • write in C++ Exercise#1: Is it a Prime? Write a program that prompts the user to...

    write in C++ Exercise#1: Is it a Prime? Write a program that prompts the user to enter a positive integer in the range [100, 100000]. If the integer is not in the specified range the program prompts the user again. The program prints whether the integer is a prime number or not. Sample input/output nter an integer in the range [10e, 10eeee]: 39 nter an integer in the range [100, 100000]: 120453 Enter an integer in the range [10e, 10e000e]:...

  • I need help with this exercise. Thank you for your help Language is C++ 6. Write...

    I need help with this exercise. Thank you for your help Language is C++ 6. Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. (Note: An even number is prime if it is 2. An odd inte- ger is prime if it is not divisible by any odd integer less than or equal to the square root of the number.)

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • C++ Problem #1 Write a program that prompts user to enter an integer up to 1000...

    C++ Problem #1 Write a program that prompts user to enter an integer up to 1000 and displays back a message about the number of digits in this number and if number is odd or even. For example, if user enters 93 message back should be "93 has 2 digits and is odd".

  • write a c++ program that prompts a user for a number then attempts to allocate an...

    write a c++ program that prompts a user for a number then attempts to allocate an array of as many integers as the user enters. In other words, the program might prompt the user with a line like: “How many integers would you like to allocate?” It should then allocate as many integers as the user enters. The program should then wait for the user to press enter before deleting the allocated array and quitting. We will use this time...

  • Java: Write a program that prompts the user to enter integers in the range 1 to...

    Java: Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The program should also prompt the user for the number of integers that will be entered. As an example, if the user enters 10 integers (10, 20, 10, 30, 40, 49, 20, 10, 25, 10), the program output would be: 10 occurs 4 times 20 occurs 2 times 25 occurs 1 time 30 occurs 1 time...

  • In C++, Write a program that it prompts to user for two integers, computes the quotient...

    In C++, Write a program that it prompts to user for two integers, computes the quotient of two integers, and then displays the result. You need to do the following things in this assignment: + The main function prompts for user input and reads the two integers that the user entered. + Write a quotient function that computes the quotient of two integers and return the results. (hint: avoid integer division and divide by zero)

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