I am new to C++ and currently am working on a project for square triangular numbers. I have the logic sorted but my program wont display anything from the cout operator, any help would be appreciated. Source is below for reference, indentation is correctly done.
Code:
#include <iostream>
using namespace std;
int main()
{
// Variable and constant declarations...
int triangle_start = 0; //start value for triangular number
int triangle_next = 1; //next sequential value added to
//triangular number
int distance = 1; //length of each side of the square
int area; //value of distance * distance
const int HOW_MANY = 4; //how many square triangular numbers printed
int count = 1; //loop counter initialized at 1
//Determining the square triangular numbers
while (count <= HOW_MANY)
{
area = distance * distance;
if (triangle_next < area) // triangular number < square
{
triangle_start += triangle_next;
triangle_next++;
}
else if (triangle_start > area) // triangular number > square
{
distance++;
}
else if (triangle_start == area) // triangular == square
{
cout << "Square triangular number" << count << "is" << area << endl;
count++;
distance++;
}
else
{
return 0;
}
}
//exit
return 0;
}