Question

I need help with this in C++

Program 2) Display and sum up all the numbers of factor of 5 in a given range. a) Request a number range (min/max values) sep

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

Program :

#include <iostream>

using namespace std;
int main()
{
   float min,max;
   int sum=0,i,count=0,t=1;
while(1)
   {
   cout<<"Specify a range of values(min/max) separated by a space:";
   cin>>min>>max;
   cout<<"\n";
   if(min==(int)min && max==(int)max)
   {
      if(min<max)
      {
         for(i=min;i<=max;i++)
         {
            if(i%5==0)
            {
            cout<<i<<" ";
            sum=sum+i;
            count++;
         }
                   }
               cout<<"\n\n"<<count<<" numbers of factor of five in the range:\n";
               cout<<"Sum = "<<sum;
               cout<<"\nAvearage = "<<sum/count;
               break;
              
           }
           else
           {
              cout<<"Max must be greater than min. Please re-enter.\n\n";
             
           }
       }
       else
       {
          cout<<"Integers are required. Please re-enter.\n\n";
       }

}

return 0;
}

Screen shot of the program :

1 #include <iostream> 3 using namespace std; 4 int main() 50 { float min, max; int sum=0,i,count=0,t=1; while(1) 96 cout<<Sp

cout<<\n\n<<count<< numbers of factor of five in the range: \n; cout<<Sum = <<sum; cout<<\nAvearage = <<sum/count; br

Output 1:

C:\Users\srinivaspc\Desktop\HomeworkLib\C programs\factor.exe Specify a range of values (min/max) separated by a space:2 36 5 10 15

Output 2:

C:\Users\srinivaspc\Desktop\HomeworkLib\C programs\factor.exe Specify a range of values (min/max) separated by a space:1.1 5.5 Inte

If you have any doubt please comment....

Please give a up vote

Thank you.....

Add a comment
Know the answer?
Add Answer to:
I need help with this in C++ Program 2) Display and sum up all the numbers...
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 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...

  • Python Script format please! 1. Write a script that takes in three integer numbers from the...

    Python Script format please! 1. Write a script that takes in three integer numbers from the user, calculates, and displays the sum, average, product, smallest, and largest of the numbers input. Important things to note: a. You cannot use the min() or max() functions, you must provide the logic yourself b. The calculated average must be displayed as an integer value (ex. If the sum of the three values is 7, the average displayed should be 2, not 2.3333). Example:...

  • Write a program that reads two integer values. It then calculates and displays the sum and...

    Write a program that reads two integer values. It then calculates and displays the sum and average of all values between them, Le. if the first value is vi and the second value is 2, then the program calculates and displays the sum and average of all values in the closed range Iv1,2 Your Program must satisfy the following constraints: A. make sure that v1 is less than 2 B. Use a function named getStats(that takes two integer yalues as...

  • Write a C++ program that simulates playing the Powerball game. The program will generate random numbers...

    Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...

  • Need a program that outputs all possible combinations of X amount of numbers depending on the...

    Need a program that outputs all possible combinations of X amount of numbers depending on the length of the password. For example it will ask the user the length of the password and if they input 3 then it will display all possible combinations from numbers 0 through 9 so the sample output will look like. 000, 001, 002, 003, 004, 005, 006, ..................................................... 994, 995, 996, 997, 998, 999 after it will ask the user if they want to...

  • need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that...

    need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...

  • Please write a C++ program that will accept 3 integer numbers from the user, and output...

    Please write a C++ program that will accept 3 integer numbers from the user, and output these 3 numbers in order, the sum, and the average of these 3 numbers. You must stop your program when the first number from the user is -7. Design Specifications: (1) You must use your full name on your output statements. (2) You must specify 3 prototypes in your program as follows: int max(int, int, int); // prototype to return maximum of 3 integers...

  • EVERYTHING IN C# Write a program that includes a method that returns the sum of all...

    EVERYTHING IN C# Write a program that includes a method that returns the sum of all the elements of an ArrayList of Integer Objects. Allow the user to enter the integers to be added to your ArrayList from the console (max of 10 integers). And also write a program that includes a method that returns the sum of all the elements of a Linked List of Integers. Allow the user to enter the integers to be added to your Linked...

  • C# Visual Studios HelloWorld For this program, you will need to sum the values of an...

    C# Visual Studios HelloWorld For this program, you will need to sum the values of an array and print the sum. A numbers array of integers will be provided for you in the program file. Since the array will already be populated with values, all your program needs to do is calculate the sum of all the values and print the output. Sample output Sum: 215

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