# Problem with program output

• 03-22-2006
progrookie
Problem with program output
Hi guys. I am having a problem with a project for my Computer Science class. The basic program works but I am having trouble getting the output the professor asked for. Here is my source code:

Code:

```#include<iostream> #include<iomanip> using namespace std; #define clear() cout << (char)(27) << '[' << '?' << '3' << 'l'; #define cur_yx(y,x) cout << (char)(27) << '[' << y << ';' << x << 'H'; main() {   int start, end, sum, square, sum_cubes, sum_terms, cubes_terms;   cout<<"Input Series Start Here: ";   cin>>start;  cout<<"Input Series End Here: ";   cin>>end;     sum_terms = start, start++;     cubes_terms = start*start*start;     cubes_terms++;   sum = (((0.5)*(end*end)) + (0.5*end));   square = sum * sum;   sum_cubes = (end*(end + 1) / 2) * (end*(end + 1) / 2);   cout<<"Sum = "<<start<<" + "<<sum_terms++<<" = "<<sum<<endl;   cout<<"Square of Sum = "<<square<<endl<<endl;   cout<<"Sum of Series Terms Cubes = "<<cubes_terms<<" = "<<sum_cubes<<endl<<en\ dl; }```
As I said, the main program works. It calculates the sum, square and sum of the cubes. However, the professor has asked for a specific output. He wants the output to say the following:

For example, if the two integers were 1 and 3, the output should
be:

Sum = 1+ 2 + 3 = 6
Square of Sum = 36

Square of Cubes = 1 + 8 + 27 = 36

What I am having trouble with is how to get the program to output 1+2+3 or 1+8+27 along with the answer, which in this is 36. Any help would be appreciated. Thanks.
• 03-22-2006
spydoor
Your program does not work correctly if the start number is not 1.

You are almost certainly going to need a loop to print the output in that format.

Code:

```    cout << "Sum: ";     for(i = start; i <= end; i++) {         cout << i;         if(i < end) cout << " + ";     }     cout << " = " << sum << endl;```
• 03-22-2006
ChaosEngine
Quote:

Originally Posted by progrookie
Code:

```#define clear() cout << (char)(27) << '[' << '?' << '3' << 'l'; #define cur_yx(y,x) cout << (char)(27) << '[' << y << ';' << x << 'H';```

ARRGGHH, my eyes, my eyes! Macros are EVIL!! somewhere between telemarketers and hitler on a scale of 1 to evil.

as spydoor said you'll need a loop to output your values, and probably a loop to calculate them too. what happens if someone inputs 1 and 9999?
• 03-22-2006
progrookie
Thanks spydoor and chaosengine. I got the desired output. Chaos, the macros were not my idea. :p The professor instructed us to place that in every program.

Thanks again guys.
• 03-22-2006
ChaosEngine
Quote:

Originally Posted by progrookie
Chaos, the macros were not my idea. :p The professor instructed us to place that in every program.

I'd look into having him fired.
• 03-23-2006
WaltP
There's worse things to fire a guy for than macros, Chaos.
Code:

`main()`
and no
Code:

`return x;`
for example.... :rolleyes:
• 03-23-2006
ChaosEngine
Quote:

Originally Posted by WaltP
There's worse things to fire a guy for than macros, Chaos.
Code:

`main()`
and no
Code:

`return x;`
for example.... :rolleyes:

that's pretty bad alright, but those could be the op's fault.
• 03-23-2006
SlyMaelstrom
Quote:

Originally Posted by ChaosEngine
that's pretty bad alright, but those could be the op's fault.

Plus I heard he seduces his students. Just what I heard... s'all I'm sayin'.