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 : ";
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;
}``````

Wrap from lines 6 thru (and including) 43 in a do/while loop. Instead of having the if and else if use c == 'y' as your condition of your do/while.

Please stop bolding your messages. If you look through these forum, you will not see messages in bold.

You start the loop just above the first line you need in the loop. That varies with every program. Usually above the initialization of values that must be set every time thru the loop, above a menu, that type of thing.

and thanks to you both :)

have you got the solution how to restart ?

commented: Wtf? +0

perhaps you didnt notice the text, right above the message entry box when you bumped this thread, that reads

This thread has been marked solved.