problem on C++ programming question

Posted on 1999-11-12
Medium Priority
Last Modified: 2010-04-01
i have a question on C++ and i can't manage to solve it out since i'm new to C++. can you help me out? this is the question.
ask a user to enter starting point. then ask the user to enter end point. add the starting point repeatly until it reach the end point or less. finally, output the result each time the addition happen and at the end of program, display the number of the addition happen.
i hope you can help me to solve this problem. thanks.
Question by:yvonnesoo
  • 4
  • 3
  • 2
  • +2
LVL 22

Expert Comment

ID: 2202752
We cannot provide answers to school assignments.  That is grounds for removal from this site.  (for both you and the experts involved.)  We can provide only limitied help in accademic assignments.    We can answer specific (direct) questions, like you might ask your teacher.  We can review your work and post suggestions, again, like your teacher might do.

Do you have specific questions?
Do you have any work on this (incomplete even) that we can review?

Expert Comment

ID: 2203382
Hmmm, the algorithm to solve the problem is written in the problem.  Break it into the steps described:

1. get start point from user
2. get end point from user
3. loop until condition (you reach end point or less); each iteration, add the start point, output the result, and increment a counter
4. output the counter

Since all of this is written in the problem, I don't think it's really your question.  But what is your question?

Expert Comment

ID: 2203906
Thank you, nietod, for trying to keep people honest.
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.


Expert Comment

ID: 2204570
As a teacher of Computer Science it seems that your question on loops fits into the cirriculum about this time, so I am not going to answer the question but I will give you the notes I would give my class.

You have to use a loop which requires 3 things:
1) the initialization of the loop
2) the stopping point of the loop
3) the incrementation of the loop

I am sure you have been taught either the while loop or the for loop.  Since the user will enter a definitive starting and ending point use the for loop.  Here is the syntax for a for loop.

for(variable = starting point; variable <=ending point ; incrementation)
any work you need to do repeatedly goes in here


I don't think your teacher would want me to give you more than that.

Author Comment

ID: 2204931
For your information, i'm not a student and i'm now working. I would like to increase my knowledge on C++ programming. But the question i request earlier is quite confuse and i can't solve it. Since, i don't know much about the string or value on C++, i need your help. Unfortunely, none of you can solve my problem. For the proposed answer, i don't know what is for loop at all.
LVL 22

Expert Comment

ID: 2205095
Student or not, its in your best interest to attempt the problem yourself and have us review your work.  

If you don't know what a "for loop", it sounds like you have NO knowledge of C++.  (This is like one of the first things you would learn in a book.)   I recommend you but a book or two on introductory C++ programming.  One I recommend is Deital and Deital's "C++ How to Program"

Do you know what a "while loop" is?  If not, how are you leaning C++?

Author Comment

ID: 2205151
i know while loop. as i said, i new to C++...and i'm seeking a person to help me out. do you understand what i'm saying about? if you are a good lectured, you will not let your client to frusfrated.
LVL 22

Expert Comment

ID: 2205169
Okay, you can do this with a while loop.  

You need to ask the user to enter the starting point and ending point.  I assume the starting point is a number, right?  You can ask the user by printing a prompt like

cout << "Please enter a starting point: ";

then you can read the valeu they entered like

int SartPoint;

cin >> StartPoint;

Can you write a program that just gets the starting and ending point?

Accepted Solution

tenetjax earned 150 total points
ID: 2205199
int start;
int end
int counter;
int sum;


for(start; start <=end; start++)


Author Comment

ID: 2205238
Thank you. I understand now. May i know beside using for loop, can i use while or do? which one is better. lastly, how do i output the result each time the addition happen? it is mean i have to enter the start and end point before the addition can happen or there are other way to do that.
LVL 22

Expert Comment

ID: 2205263
>> May i know beside using for loop, can i
>> use while or do

>> which one is better
Choice between the "for" loop or eiher the "while" or "do" loops is a matter of preference.  A "for" will be the shortest, that is, it takes less lines of code than "while" or "do".  The choice between "while" and "do" is a little harder.  A "while" and a "do" loop are almost identical, except that a "do" loop will allways execute at least 1 iteration (because it tests after it completes an iteration), a "while"  loop might not perform even the first iteration (because it tests before each iteration).  So to choose between them you have to consider whethor or not you want the loop to always execture at least one time.  You have to ask youself are the times when the loop should never run even once?

>>  how do i output the result each time the
>> addition happen
The program already does that.  It uses


to do this.

>> i have to enter the start and end point before the
>> addition can happen or there are other way to do that
Of course you have to enter it first.  Otherwise the program doesn't know where to start/  In other words, it doesn't know what numbers to add unless it is told before it has to add them.  Its no different than a human.  You can't tell a human "Add two numbers, and when you tell me the result, I'll tell you which two numbers to add."  the same with a computer.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question