# Thread: Totally stuck where have i gone wrong??

1. ## Totally stuck where have i gone wrong??

Hey all, currently i am doing this question
Write a C++ program such that its execution will keep asking the user to enter a pair of integers, start and finish, and will terminate when either start>finish, or EOF or an invalid input has been encountered. Every time a new pair of integers start and finish are read, the program will first calculate the subtotal
start2 + (start+1)2 + (start+2)2 + ... + (finish-1)2 + finish2and then add the subtotal to the total. Before the program terminates, it should display the accumulatedtotal and the average of all the subtotals.
This is the code i have managed to get so get so far

Code:
```#include <iostream>#include <cmath>
// #include <string>
using namespace std;

int main()
{
double start, finish, subtotal, total, average;
float a, b, c ;

bool ValidInput = false;

do
{
cout << "Enter the START and FINISH number: ";
cin >> a, b ;

c = pow(a , b);

cout << a << "to the power of " << b << "equals to" << c
<< '_' << endl << endl;

if (cin.fail() || start < finish)
{
cin.clear();
cin.ignore();
return 0;

}
else
{
double total;
total = start + finish;

cout << "The Subtotal Is : " << subtotal << endl;
cout << "The Total Is: " << total << endl;
cout << "The average is: " << average << endl;
}

} while ( ValidInput == false );

system ("pause");
return 0;

}```

2. A wild guess is that you're quite new to c++. The one on one is, debug. Use cout, printf() flush could be used too, to display your variables as you go along. So, first lesson: debugging and some brute force.

yes i am quite new to c plus plus and been thrown into the deep end.
where am i supposed to do the de bugging? e.g cout print f ()

4. Originally Posted by überfuzz
A wild guess is that you're quite new to c++. The one on one is, debug. Use cout, printf() flush could be used too, to display your variables as you go along. So, first lesson: debugging and some brute force.
It is ok to use a few output statements as a basic ' debug ' but you really shouldlearn to use the actual debugger that it is assumed you have also in your toolchain, so you can run the program in debug mode and watch the variables changing, step through the program a line at a time etc. What do you write your code and build with? IDE like code:blocks? please don't say turbo c !

5. ## Reposnse to rogster

I use dev c ++ how do i get the debugging mode set up?
I just looked at the code again and think it is best to rewrite it again any tips to get me started off.

6. I thought i had replied to this but it seems my response has disappeared. Anyway, I said do not use Dev C++ as it is no longer up to date, get code blocks 10.05 or similar. i dont know what the debug key is in dev++ but you will find it by looking at the options in the menu bar. Also you will probably need your program to be in a project for the debugger to work, ie that you are not just making a single new file and then compiling it and running it.

7. Originally Posted by rogster001
I thought i had replied to this but it seems my response has disappeared.
Dude, you're obviously helping a newbie here. I guess your sarcasm will score better if you try it later on.

8. Originally Posted by geekified
I just looked at the code again and think it is best to rewrite it again any tips to get me started off.
There are many ways of planing a program. I always go with a piece of paper and a pen. Try to find out what works best for you.

9. ## ?

Originally Posted by überfuzz
Dude, you're obviously helping a newbie here. I guess your sarcasm will score better if you try it later on.
- Dude - there was no sarcasm, I honestly meant I went back to view the post and the reply did not seem to have been added, I would not bash a newbie that shows code and effort, I have certainly been there myself too rite, so keep it in your pants next time before dishing out .

10. Originally Posted by rogster001
- Dude - there was no sarcasm, I honestly meant I went back to view the post and the reply did not seem to have been added, I would not bash a newbie that shows code and effort, I have certainly been there myself too rite, so keep it in your pants next time before dishing out .
Pfft! I pretty sure you could feel the warm tenderness in my post.

11. The original poster may not have, and thought i was bashing after your comment is all, me piro vampiro.