Hi,
I have a quick question...so I have this program that asks user to enter an integer and then it analyzes that integer..it outputs factors of that number, and tells whether its composite or prime, abundant or deficient, and so on...and then after telling few things about that number..it asks the user whether they want to analyze another number and if user enters "y" it would start again and if they enter "n" it would stop the program..but I can't remember how to start the program again...I know I'm suppose to use a loop but I can't quite remember where I'm suppose to start the loop...
Here is some of my code..if someone can please tell me where to enter the loop I would be very grateful..
int main()
{
char c;
int num, a, p, newNum;
int sum = 0;
cout << "Please enter a positive integer: ";
cin >> num;
cout << "Factors of " << num << " are : ";
//add function to calculate factors
cout << endl;
cout << "Sum of factors of " << num << " is : " << sum << endl;
a = sum - 1;
if ( a == num )
cout << num << " is prime." << endl;
else
cout << num << " is composite." << endl;
cout << "The Prime factorization is: ";
//prime factorization loop
cout << endl;
// Check if number is even or odd.
if ( num % 2 == 0 )
cout << num << " is an even number." << endl;
else if ( num % 2 != 0 )
cout << num << " is an odd number." << endl;
// Check if number is perfect, deficient, or abundant.
if ( sum == num )
cout << num << " is a perfect number." << endl;
else if ( sum < num )
cout << num << " is a deficient number." << endl;
else if ( sum > num )
cout << num << " is an abundant number." << endl;
cout << " Would you like to analyze an integer? (y/n) ";
cin >> c;
if ( c == 'y' )
??
else if ( c == 'n' )
cout << "Thank you for using Integer Analyzer!! " << endl;
return 0;
}
Thanks in advance!!