Looping yes or no while storing a value and reusing it.

How do i get a program such as below to repeat itself until it terminates if Money is less than the cost of the Laptop? And print out its new remainder for everytime the user buys again?

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
#include <iostream>

using namespace std;

int main()
{
    int Remainder;
    int Laptop(1000);
    int Money(3000);
    cout<< "You have $3000 in your wallet." << endl;
    cout << "Buy a laptop that costs $1000? (y/n)" << endl;
    char response;
    cin >> response;
    bool x = true;

    while(x)
{
restart:
    if (response == 'y' || response == 'Y')
    {
    Remainder = Money - Laptop;
    cout << "you have $ " << Remainder << "left" << endl;
    }

    else if (response == 'y' || response == 'Y')
    {
    Remainder = Money - Laptop;
    cout << "you have $ " << Remainder << "left" << endl;
    }

    else break;

    cout << "buy again? (y,n)" << endl;
    cin >> response;
    if (response == 'y' || response == 'Y')
        goto restart;


    x++;
    }


    return 0;
}


Topic archived. No new replies allowed.