Question

In C++ Prompts the user to enter 5 numbers. Once the user has entered the 5...

In C++ Prompts the user to enter 5 numbers. Once the user has entered the 5 numbers, the program should calculate and display the average of the 5 numbers.and no for(;;) while(1) while(true) do{//code}while(1); without cin The program prompts the user for one number at a time

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

If we are not using cin, then we have to use scanf() function to get the input from the user. In this program, we created only two variables total_sum to keep adding the number to it and number to store the new number from the user.

In the end, we divide the total_sum by 5 and store it again in the total_sum variable and print it in the console.

Please Note: (I have not used for, while, do while and also cin )

here is the C++ code

-----------------------------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>

#include<iostream>

int main()
{
// it will store the total sum of the 5 numbers
double total_sum=0;
// to store the next user number
double number=0;

printf("Enter a number: ");
scanf("%lf",&number);
total_sum += number;
  
printf("Enter a number: ");
scanf("%lf",&number);
total_sum +=number;
  
printf("Enter a number: ");
scanf("%lf",&number);
total_sum+=number;
  
printf("Enter a number: ");
scanf("%lf",&number);
total_sum+=number;
  
printf("Enter a number: ");
scanf("%lf",&number);
total_sum+=number;


// compute average and print
printf("\nAverage of these numbers: %.2f",total_sum/5);

}

-----------------------------------------------------------------------------------------------------------------------------------------------

thank you !

Add a comment
Know the answer?
Add Answer to:
In C++ Prompts the user to enter 5 numbers. Once the user has entered the 5...
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
  • In C++ Prompts the user to enter 5 numbers. Once the user has entered the 5...

    In C++ Prompts the user to enter 5 numbers. Once the user has entered the 5 numbers, the program should calculate and display the average of the 5 numbers.and The program prompts the user for one number at a time, without using for

  • MATLAB QUESTION 8) Create a program that first prompts the user to enter any two numbers....

    MATLAB QUESTION 8) Create a program that first prompts the user to enter any two numbers. Then prompt the user again to input as many numbers as they choose. Stop the program by inputting-1. Then, display the largest number and second largest number in the command window once the user kills the program. The built-in max function cannot be used. The figure below is an example of what the command window should look like when the code is ran. First...

  • Assignment Develop a program to analyze one or more numbers entered by a user. The user...

    Assignment Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. Input should be limited to numbers from 1 through 1000. Determine if a number is a prime number or not. A prime number is one whose only exact divisors are 1 and the number itself (such as 2, 3, 5, 7, etc.). For non-prime numbers, output a list of all divisors of the number. Format your...

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

  • Write a program that allows the user to enter a series of exam scores. The number...

    Write a program that allows the user to enter a series of exam scores. The number of scores the user can enter is not fixed; they can enter any number of scores they want. The exam scores can be either integers or floats. Then, once the user has entered all the scores they want, your program will calculate and print the average of those scores. After printing the average, the program should terminate. You need to use a while loop...

  • 5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters...

    5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below. ​ 1 largest = None 2 smallest = None 3 while True: 4...

  • Write a C++ program that prompts a user to enter a temperature in Fahrenheit as a...

    Write a C++ program that prompts a user to enter a temperature in Fahrenheit as a real number. After the temperature is entered display the temperature in Celsius. Your program will then prompt the user if they want to continue. If the character n or N is entered the program will stop; otherwise, the program will continue. After your program stops accepting temperatures display the average of all the temperatures entered in both Fahrenheit and Celsius. Be sure to use...

  • Prepare pseudocode for a program that lets a user continuously enter numbers until the number 99...

    Prepare pseudocode for a program that lets a user continuously enter numbers until the number 99 is entered. Once the user has stopped entering numbers, display the number of numbers entered AND the sum of those numbers. You'll need a counter and an accumulator for this (see pp. 179-181 and 205-208). Make sure your loop is structured (see priming input in figure 3-16). Don't forget to comment your code. Don't forget to display appropriate prompts when requesting input from the...

  • Using C++ Design a program that Prompts the user to enter in 4 numbers, then have...

    Using C++ Design a program that Prompts the user to enter in 4 numbers, then have the program arrange the numbers entered in Ascending order using "if" statements to complete the task...

  • c++ Write a program that prompts the user to enter a length in feet and then...

    c++ Write a program that prompts the user to enter a length in feet and then enter a length in inches and outputs the equivalent length in centimeters. If the user enters a negative number or a non-digit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers. Your error message should read A non positive number is entered and allow the user to try again.

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