i cant figure out how to make a program that solves the sum of integers between two input numbers. i can only use do/while, if/else,c++/C--. the basic stuff.


EX: Starting number:25
Ending number:47
The sum of the integers between 25 and 47 is 828.

____________________________________________________

Please post quickly i need to get this done!!!!!

Recommended Answers

All 13 Replies

this program is wicked easy.. at least try to make an attempt on your own.

this program is wicked easy.. at least try to make an attempt on your own.

i have, i just started c++ and i can't do it i already try for hours

#include<iostream>
using namespace std;

int main()
{
     //declare a couple of int variables
     //initialize your variables

     //cout a prompt for the user to enter the lower boundry
     //cin the user's input into one of your previously declared int variables

     //cout a prompt for a user to enter the upper boundry
     //cin the user's response into one of your previously declared int variables

     //use a loop with a counter starting value equal to the lower boundry
          //accumulate += the lower boundry until it equals the upper boundry

     //cout your final answer

    return 0;
}

umm i dont know how to do that. can u just do the basic program?

Have to follow forum policy:

We only give homework help to those who show effort
Jun 8th 2004 until Jul 9th 2008


This forum is meant for discussing programming languages in addition to exchanging code and algorithms. However, it has become a problem where too many students are posting homework problems expecting a quick solution without ever trying for themselves. Not only does this constitute cheating, but it is very discouraging, frustrating, and annoying to everyone who takes valuable time to answer programming support questions.

Though we are all here to help, please don't expect quick solutions to your homework. We'll help you get started, exchange algorithm ideas, how-to's, etc. but only if you show that you're willing to put in effort as well.

For more information about this, click this link or this link.

Thanks for understanding and for your cooperation! These rules are here to make DaniWeb a student-friendly place to learn.

i have been trying this program for hours! i cant do it jeez i am on my knees....

post what you have so far.. and we can make suggestions.

#include <iostream.h>
#include <conio.h>


int main()
{
int num,num2,sum,num3;
do
{
cout<<"Enter starting number";
cin>>num;
cout<<"Enter ending number";
cin>>num2;

sum=num+num++;
cout<<num<<endl;
cout<<"the sum is: "<<sum<<endl;
}while(num<num2+1);
return(0);
}

This works, with only minor changes to your original code. Remember that things you do once are outside of the loop, the sum has to start at 0 to give you any useful information, and the basic idea is to add num to sum until num equals num2.

#include <iostream>

using namespace std;

int main()
{
  int num,num2,sum = 0;

  cout<<"Enter starting number";
  cin>>num;
  cout<<"Enter ending number";
  cin>>num2;

  do
  {
    sum=sum+num++;
  }while(num<num2+1);

  cout<<"the sum is: "<<sum<<endl;

  return(0);
}

By the way, your whiney attitude gets on my nerves, and I doubt I'm the only one.

i dont knwo how to do it, i been tryin for hours, i seriosly dont know how to do it. i've been trying different ways and things

im a freshman ina jr-senior class my parents forced me into this and i need help, i am not lying, i have spent half my weekend on this. you think i am having fun?

thank you so much, you don't even know how long this has been going on!

>you think i am having fun?
I don't care. I don't need your life story, I don't want to hear how long you've been programming or how long you've been working on the problem. Are you expecting us to feel sorry for you and rush to help you? Your pleas for help are irritating, a turn-off to prospective helpers.

Ask a question with just the facts and you'll get an answer with just the facts. Quick, simple, and very efficient. That's how things work here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.