How do I change it so that it will only say how many times the program has ran once I typed another key then y.
Output:
=================================
Programmer Name: Peter Langlands
Program 3 Description:
CS 150 Spring 2011 Lab CRN:
Date:
=================================
Enter an nonnegative number: 10
a0 = 10
a1 = 5
a2 = 16
a3 = 8
a4 = 4
a5 = 2
a6 = 1
The integer k such tha a_k = 1 is:
The sum of the series equals:
The largest number of the sequence is:
The largest number in the sequence is in position:
There are ? odd values in the sequence.
There are ? even values in the sequence.
=================================
Would you like to run this program again?
Enter Y or y to continue, or any other key to exit: y
=================================
Thanks for using the super sequence analyzer!
This progam has ran 1 times.
=================================
Programmer Name: Peter Langlands
Program 3 Description:
CS 150 Spring 2011 Lab CRN:
Date:
=================================
Enter an nonnegative number: 2
a0 = 2
a1 = 1
a2 = 8
a3 = 0
a4 = -4
a5 = -6
a6 = -7
The integer k such tha a_k = 1 is:
The sum of the series equals:
The largest number of the sequence is:
The largest number in the sequence is in position:
There are ? odd values in the sequence.
There are ? even values in the sequence.
=================================
Would you like to run this program again?
Enter Y or y to continue, or any other key to exit: n
=================================
Thanks for using the super sequence analyzer!
This progam has ran 2 times.
=================================
Press any key to continue . . .
#include <iostream>
using namespace std;
void printInfo();
int howMany();
int nonNegative(int num);
int main()
{
int num;
char choice = 'Y';
cout << "=================================\n" << endl;
while(choice == 'Y' || choice == 'y')
{
printInfo();
nonNegative(num);
cout << "=================================\n" << endl;
cout << "Would you like to run this program again? " << endl;
cout << "Enter Y or y to continue, or any other key to exit: ";
cin >> choice;
howMany();
}
system("pause");
return 0;
}
//==================================================================//
void printInfo()
{
cout << "Programmer Name: Peter Langlands\n"
<< "Program 3 Description:\n"
<< "CS 150 Spring 2011 Lab CRN:\n"
<< "Date:" << endl;
cout << "=================================\n" << endl;
}
//==================================================================//
int nonNegative(int num)
{
cout << "Enter an nonnegative number: ";
cin >> num;
cout << "a0 = " << num << endl;
cout << "a1 = " << num / 2 << endl;
cout << "a2 = " << num + 6 << endl;
cout << "a3 = " << num - 2 << endl;
cout << "a4 = " << num - 6 << endl;
cout << "a5 = " << num - 8 << endl;
cout << "a6 = " << num - 9 << endl;
cout << "\nThe integer k such tha a_k = 1 is:" << endl;
cout << "The sum of the series equals:" << endl;
cout << "The largest number of the sequence is:" << endl;
cout << "The largest number in the sequence is in position:" << endl;
cout << "There are ? odd values in the sequence." << endl;
cout << "There are ? even values in the sequence." << endl;
}
//==================================================================//
int howMany()
{
static int count = 0;
count++;
cout << "=================================" << endl;
cout << "\nThanks for using the super sequence analyzer!" << endl;
cout << "This progam has ran " << count << " times." << endl;
cout << "=================================\n" << endl;
}
//==================================================================//