Please help. My while loop is the problem. I want to use a non-recursive function to make the triangle number the sum of all whole numbers from 1 to N.
#include "stdafx.h"
#include <iostream>
using namespace std;
int triangle(int t);
int main()
{
int i;
cout << "Enter a number please.";
cin >> i;
cout << endl;
cout << "triangle(" << i << "); " << triangle(i) << "\n\n";
system("PAUSE");
return 0;
}
int triangle(int t);
int i;
{
while (t >= 1)
{
cout << i << end;
i = i - 1;
}
}
Line 24-25: i is uninitialized. You're going to print and decrement garbage.
Line 24: This should be endl
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.