In this program you can type in any non-negative integer and it will go through the formulas inside the program and give you an output. the program runs perfectly fine if you want to compile and run it, but how can i find the sum of the numbers that are output? i tried adding a sum formula in the while loop, but it only added up the last two numbers.
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
void Calculate();
void ContinueRun();
void CheckItOut();
int main()
{
Calculate();
ContinueRun();
}
//////////////////////////////////////////////////////////////
void Calculate()
{
int x;
int a;
int y;
int sum;
int sub;
int even;
int odd;
sub = 0;
even = 0;
odd = 0;
cout << "*************************************************" << endl << endl;
cout << "Please Enter A Nonnegative Integer: ";
cin >> x;
cout << "You Entered: " << x << endl;
while (x > 1)
{
if (x % 2 == 0)
{
a = x / 2;
cout << "a" << sub << "= " << x << endl;
x = a;
even++;
}
else
{
a = 3 * x + 1;
cout << "a" << sub << "= " << x << endl;
x = a;
odd++;
}
sub++;
}
cout << "a" << sub << "= " << x << endl << endl << endl;
odd++;
cout << "The integer k such that a_k=1 is " << sub << endl;
cout << "The number of even integers were " << even << endl;
cout << "The number of odd integers were " << odd << endl;
cout << "The sum of the numbers is " << sum << endl;
}
////////////////////////////////////////////////////////////////////////////////
void ContinueRun()
{
int count;
int time;
char answer;
time = 1;
count = 1;
while (time == 1)
{
cout << endl << "Would You Like To Run The Program Again? (Y/N) ";
cin >> answer;
cout << endl;
if (answer == 'y' || answer == 'Y')
{
Calculate();
cout << endl << endl;
time = 1;
count++;
}
else
{
cout << "The Program Was Run " << count << " Times." << endl << endl;
time = 0;
system ("pause");
}
}
}
////////////////////////////////////////////////////////////////////////////////
void CheckItOut()
{
}