How would i get this to start again?

hey guys... I wanna know how i would get a "would you like to start again? Y or N?" message to pop up at the end of my program and have it start from the beginning is the input is Y or y and to close if the unput is N or n..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{
    system("TITLE Pythagoren theorem solver - BY: Matthew Goulart - 2008");
    system("COLOR 8");
    char loop = 'y';
    double a;
    double b;
    double H;
    
    cout<<"Welcome to the PYTHAGOREAN THEOREM problem solver by Matthew Goulart." <<endl;
    cout<<"Enter the 'a' and 'b' variables and press return!."<<endl<<endl;
    cout<<"=====================PYTHAGOREAN THEOREM problem solver====================="<<endl<<endl;
    cout<<"What is the value of A?: ";
    cin>> a;
    cout<<"what is the value of B?: ";
    cin>> b;
    cout<<"The length of the hypotenuse is:  ";
    H=sqrt(pow(a,2)+pow(b,2));
    cout<<H <<endl;


    if(a<=0)
    {
           cout<<"SIDE A IS INVALID! (no negatives)"<<endl<<endl;
    }
    else
    {
           if(b<=0)
           {
                  cout<<"SIDE B IS INVALID! (no negatives)"<<endl<<endl;
           }  
           else
           {
               if(H>0)
               {
                      cout<<"Equation successeful! "<<endl<<endl;
               } 
               }
}

    system("PAUSE");
    return 0;
}
Move everything after your call's to system() into another function. Then in main just loop.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void pythagorean()
  {
  double a;
  double b;
  ...
  }

int main()
  {
  char again;

  system("TITLE Pythagoren theorem solver - BY: Matthew Goulart - 2008");
  system("COLOR 8");

  do {
    pythagorean();

    cout << "Would you like to do it again? ";
    cin >> again;
    cin.ignore( 1000, '\n' );
    }
  while ((again == 'Y') || (again == 'y'));

  system("PAUSE");  // you don't actually need this line anymore...
  return 0;
  }


Hope this helps.
Well, thanks firstly for the quick response, but unfortunately, it is my very first day with C++ (not programming mind you) and you left a bit too much of my own code out for me to be able to find my way around... Wich is good, if you could explain, in the greatest detail possible, exactly what i am supposed to do instead of giving me the answer, I would be very greatful!
Last edited on
Move everything between system("COLOR 8") and system("PAUSE") to the pythagorean() function.

Don't forget to add your #includes and using namespace std; to the top of your file.
Thanks so very much! I GOT IT! Great to see someone who helps without flames! :)
Topic archived. No new replies allowed.