#include <iostream>
using namespace std;
int main()
{
int sum = 0; // Declare an int variable sum to accumulate the numbers
int lowerbound; // Set the initial sum to 0
int upperbound; // Sum from 1 to this upperbound
// Prompt user for an upperbound
cout << "Enter a integer: ";
cin >> upperbound;
cout << "Enter another integer: ";
cin >> lowerbound;
while (lowerbound <= 100 && upperbound <= 100)
{
sum = sum + upperbound++ + lowerbound++;
}
// Print the result
cout << "The total of the numbers " << upperbound << " and " << lowerbound << " is " << sum << endl;
}
garber
-3
Newbie Poster
Recommended Answers
Jump to PostIs there a problem? If so, please explain it. If not, this should be moved to Code Snippets.
Jump to PostWhy bother with user input on the lowerbound? and not just initialize it to 1, and then have.
while(lowerbound!=upperbound) { sum+=lowerbound; lowerbound++; }
Maybe I am miss understanding your problem.
Jump to PostI suggest replacing user input with hard coded values for testing. You should also tell us the expected output and the current output.
Have you tried stepping through the code with a debugger? This would be where I would start.
Actually, I would start with this line:
Jump to Postadd xLow to sum
That will sum all numbers between 50 and 90
Jump to PostIf the attitude of helping disgusts you, go somewhere else.
People are wasting their time on you.
All 18 Replies
daviddoria
334
Posting Virtuoso
Featured Poster
garber
-3
Newbie Poster
TheSassyDragon
0
Newbie Poster
daviddoria
334
Posting Virtuoso
Featured Poster
garber
-3
Newbie Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
TheSassyDragon
0
Newbie Poster
garber
-3
Newbie Poster
Caligulaminus
35
Junior Poster
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
Despairy
0
Light Poster
garber
-3
Newbie Poster
daviddoria
commented:
Still not listening to the suggestions! Give it another try and we can try to guide you. This problem is so short that we can't really help anymore without flat out writing it for you.
-3
Blackiey
0
Junior Poster in Training
daviddoria
334
Posting Virtuoso
Featured Poster
mir wasif
0
Newbie Poster
daviddoria
334
Posting Virtuoso
Featured Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
mir wasif
0
Newbie Poster
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.