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!!

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.

oops sorry about that..
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.
Perhaps start a new thread instead?

it's bad form to reopen someone else's solved or closed threads. unless you have a specific question precisely about the original post or one of the responses to the original post. In which case you need to make your question or comment very specific and clear, so that it's relevance is apparent to all.

please do not just wake up some old post with a generic "hey did this work?" question.

Instead, formulate your own question that relates to what you are doing, and supply a short and concise code example of what you're trying to do, and put it all in a new thread.

.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.