You are here:

C++/C program

Advertisement


Question
Hi! i have a code running but i want to know, how do i run the program and in the end it asks the user if he wants to run the program again and if yes run it again with the new values he inputs or exit he doesn't want to. My program asks user few values and displays the result.

Thank You

Answer
Put the code for your program in a simple loop, which repeats if the user answers 'y' to the question "do you want run the program again?

#include <iostream>

int main()
{
   char again = 'y' ;
   while( again == 'y' )
   {
       // your program code here


       std::cout << "do you want run the program again? (y/n) " ;
       std::cin >> again ;
       if( again == 'Y' ) again = 'y' ;
   }
}

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.