Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a function called sumTo which takes an integer parameter and returns the total of all of the numbers from 1 to that number. For

Create a function calledsumTowhich takes an integer parameter and returns the total of all of the numbers from 1 to that number. For example, if the user entered a 5, the function would calculate 1 + 2 + 3 + 4 + 5 = 15. Keep prompting the user for a number until a zero (0) is entered. Use the following run as an example:

Enter a number: 5 sums to 15 Enter a number: 25 sums to 325 Enter a number: 100 sums to 5050 Enter a number: 0 

====================YOUROUTPUT=====================

0001:Enter~a~number:~5

0002:5~is~15

===================MISMATCHFOUNDONLINE0002:===================

ACTUAL:5~is~15

EXPECTED:5~sums~to~15

#include

#include

using namespace std;

int sumTo(int number) {

int counter = 1;

int total = 0;

while (counter <= number) {

total = total + counter;

counter = counter + 1;

}

return total;

}

int main() {

int answer;

int number = 1;

while (number != 0) {

cout <<"Enter a number: ";

cin >>number;

cout<

if (number != 0) {

answer = sumTo(number);

cout<<" " << number <<" is " << answer<< endl;

}

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

6 Identify the major social criticisms of marketing.

Answered: 1 week ago