Sorry for being a little harsh, but it looks like you're just asking us to solve the problems for you. The code they're giving you is seriously outdated, filled with a lot of errors, and doesn't seem to have any kind of formatting. I would strongly suggest that if you're going to attempt to learn the language, you learn more about the fundamentals of the language before just attempting to answer questions. I would highly recommend starting with the tutorial on this site as it would have answered most of the questions that you asked us, and will help you have a better understanding of C++.
Also, if you're going to continue to post questions that have code in them, please, please use the [
code][/code] tags. This maintains the code's formatting, and helps with syntax highlighting.
Using giblit's example:
[
code]//in your main function...
int sum2 = 0; //doesn't reset each time
//lifetime is longer than the loops
for(int i = 1; i <7; ++i)
{
int sum = 0;
for(int j = last; j > 0; --j) //questionable
{
sum += j;
sum2 += sum;
std::cout << sum << ' ' << sum2 << std::endl;
}
}[/code]
Becomes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
//in your main function...
int sum2 = 0; //doesn't reset each time
//lifetime is longer than the loops
for(int i = 1; i <7; ++i)
{
int sum = 0;
for(int j = last; j > 0; --j) //questionable
{
sum += j;
sum2 += sum;
std::cout << sum << ' ' << sum2 << std::endl;
}
}
|
See how much nicer that looks? To use the code tags, you can type them exactly how they're shown above ([
code][/code]) or by clicking the "<>" button to the left of the reply window where it says "Format:". This will help the community out by allowing us to easily read your code and assist much faster and more helpful.