Question

Prompt the user for two numbers, call them "x" and "y". "x" must be less than...

Prompt the user for two numbers, call them "x" and "y". "x" must be less than "y" or reject the entry and stop the program. Otherwise, add up all of the numbers between "x" and "y" and display the result. For example:

Enter x: 10
Enter y, larger than x: 20
Total + 10 = 10
Total + 11 = 21
Total + 12 = 33
Total + 13 = 46
Total + 14 = 60
Total + 15 = 75
Total + 16 = 91
Total + 17 = 108
Total + 18 = 126
Total + 19 = 145
The answer is 145
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include«iostream» using namespace std; int main( int x, y int total-0; cout<Enterx:; cout<<Entery, larger thanx:; cin>>y

sample output:

Editable code:

#include<iostream>
using namespace std;

int main()
{

int x, y;
   int total = 0;
cout<<"Enter x: ";
cin>>x;
cout<<"Enter y, larger than x: ";
cin>>y;
if(x>y)
{
    
      cout<<"Ignore";
}

else
{

for (int i=x; i<y; i++)
{
      total+=i;

      cout<<"total+"<<i<<"="<<total<<endl;


}

    cout<<"The answer is "<< total;
}

return 0;
}

Add a comment
Know the answer?
Add Answer to:
Prompt the user for two numbers, call them "x" and "y". "x" must be less than...
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
  • 1. prompt a user to enter10 numbers. 2..If the user enters anything other than number 10,...

    1. prompt a user to enter10 numbers. 2..If the user enters anything other than number 10, remind her that only numbers are required that let her retry. 3. Do not allow the user to enter more than 10 or less than 10. 4. Display the 10 numbers back to the user at the end. 5.Calculate the following statistics from the 10 numbers entered. Minimum maximum mean range variance standard deviation

  • 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

  • Write a C++ program that prompts the user to enter two numbers. Then prompt the user...

    Write a C++ program that prompts the user to enter two numbers. Then prompt the user to select from the following options: a. Add the numbers. b. Multiply the numbers. c. Terminate the program Use the appropriate control structures (loops, if else, switch-case, etc) to make your program as short and efficient as possible. Minor syntax errors are forgiven in this exercise; just focus on the correct structure, declarations and sequence of instructions

  • 1. print mesage to user to prompt user to enter 10 numbers 2 have program accept...

    1. print mesage to user to prompt user to enter 10 numbers 2 have program accept 10 numbers from user and populate 10 occurrances of an array (use a loop to do this). 3. print message to user to advise user contents of array follows 4. have program display array contents (use loop to do this) end program comment in java please

  • 1) Write a MATLAB script to prompt a user to input two numbers, then assess whether...

    1) Write a MATLAB script to prompt a user to input two numbers, then assess whether the two numbers are equal or not. If the two numbers are equal, display that they are equal in the Command Window. If they are not equal, display that they are not equal in the Command Window. 2) Write a MATLAB script that prompts the user to enter the day of the week using the input function. If the information the user enters is...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user 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...

  • Write a program that prompt the user to enter 3 integers: x,y and z. Your program...

    Write a program that prompt the user to enter 3 integers: x,y and z. Your program should output the answer to the user based on the divisibility of x and y by z as follows: Input If both x and y are divisible by z Result X and y are both divisible by 2. X is divisible by z. Y is divisible by z. Both X and Y are not divisible by If x is only divisible by z If...

  • Assembly Language////Write a program that read in 10 integers from the user. Save the numbers into...

    Assembly Language////Write a program that read in 10 integers from the user. Save the numbers into an array; reverse the array and display the reversed array. .data arrayInt DWORD 10 DUP(?) Your program consists of 4 procedures: 1. main procedure: call procedures getInput, reverseArray, displayArray 2. getInput procedure: prompt user to enter 10 integer numbers, save the numbers into the memory for the arrayInt 3. reverseArray: reverse arrayInt 4. displayArray: display the reversed array

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

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