Question

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

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

The solution to your problem is:-

As there is no mention of any programming language I have used python as my programming language.

code for the above program is:-

s=0 # used for storing addition result.
while(True): # running an infinite loop.
   k=int(input("enter a positive number: ")) # taking input from the user.
   if(k>0): # checking the number is a positive is or not.
       s=s+k # if it is true then add the numbers.
   elif(k==0): # if it is 0 then stop asking the numbers and add them
       break   
   else:
       print("Please enter a positive number ") # if is the negative number it will prompt the user to enter a positive number again and again

print(s) # printing the sum.

Output for the above program is:-


Thank you.

Add a comment
Know the answer?
Add Answer to:
1. Write a program to add positive numbers. Ask the user to enter numbers greater 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. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The...

    1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The program should use the for loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. If the user enters a zero or negative number, a message should be given and the program should not continue (see Sample Run...

  • In C++ 2. Write a program that allows the user to enter a series of positive...

    In C++ 2. Write a program that allows the user to enter a series of positive numbers between 1 and 100 and displays the smallest and largest of the numbers entered. The program should not store the numbers that were entered, only keep track of the smallest and largest ones. The program should continue accepting numbers until the value 0 is entered and then display the results. If a number out of range is entered, tell the user it is...

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

  • In C language using printf and scanf statements: Write a program to display a histogram based...

    In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...

  • Write a program that accepts numbers entered by the user until the user enters a zero....

    Write a program that accepts numbers entered by the user until the user enters a zero. The program then must display the largest value that is smaller than zero. This should be java program

  • For Java - Write a program that creates an array of 10 integers. Ask the user...

    For Java - Write a program that creates an array of 10 integers. Ask the user to enter the subscript (index) of an element, then displays the element located at that subscript. If the subscript entered is out of bounds (less than 0 or greater than length - 1), display the message "Out of Bounds".

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

  • In this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

  • use C++ to write the following program. needs to ask the user for n The user...

    use C++ to write the following program. needs to ask the user for n The user must put in those 5 values, probably using a for loop. NOTE: You can assume the number of values to be entered is 5. My attempted program below: (not correct, but just a basis) 4. Larger Than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume that the array contains...

  • This MUST be done in C++ Write a program with a loop to ask the user...

    This MUST be done in C++ Write a program with a loop to ask the user for an integer greater than or equal to 2 and then pass the integer to a function which will produce and display on the console the ulam sequence1. Do not accept a number less than 2. 1The ulam sequence begins with an integer. If it is even, divide by 2. If it is odd, multiply by 3 and add 1. Then apply the appropriate...

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