y/n while loop

I can't seem to get a y/n while loop to work no matter what I do.
I am JUST starting, so please put it in simple terms....


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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//Calculates GCF and LCD from user input repeatedly

# include <iostream.h>     //needed for text
using namespace std;
int getGCF(int x, int y)
{ 
   int  z;
   while (y != 0) 
   {
      z = x % y;
      x = y;
      y = z;
   }
   return x;
} 
int main ()
{
    char repeat = 'y';
    while (repeat == 'y')
    {
         int A, B, D, repeat;
         int thousandfctrA, thousandfctrB;
       
         cout << "This program calculates the GCF and LCM of two integers. ";
         cout << endl;
         cout << endl;
         cout << "Please enter the first positive integer. ";
         cout << endl;
         cin >> A;
         cout << endl;
         thousandfctrA=A*1000;
             while (A<=0 || (thousandfctrA%1000)!=0)
             {
                   cout << "That is not a positive integer. ";
                   cout << endl;
                   cout << "Please enter the first positive integer. ";
                   cout << endl;
                   cin >> A;
                   cout << endl;
             } 
             
         //if input is correct
         
         cout << "Please enter the second integer. ";
         cout << endl;
         cin >> B;
         cout << endl;
         thousandfctrB=B*1000;
              while (B<=0 || (thousandfctrB%1000)!=0)
             {
                   cout << "That is not a positive integer. ";
                   cout << endl;
                   cout << "Please enter the second positive integer. ";
                   cout << endl;
                   cin >> B;
                   cout << endl;
             }     
             
         //for correct input
         
         cout << "The GCF of " <<A<< " and " <<B<< " is " <<getGCF(A,B)<< endl;
         cout << endl;
              D=(A*B)/getGCF(A, B);    //LCM equation
         cout << "The LCM of " <<A<< " and " <<B<< " is " <<D<< endl;
         cout << endl;
         cin.clear();
         cout << "Do you wish to calculate again? ";
         cout << endl;
         cout << "If so, press 'y'. If not, enter 'n'.  ";
         cin >> repeat;
         cout << endl;
         cout << endl;
    }
    
    int enter;
    cout << "Bye!";
    cin.clear();
    cin >> enter;
    return 0;
}
line 21 try this int A, B, D;
Don't use iostream.h it is depreciated. Instead use iostream.
@Jamerack

Hm... I didn't know that. What is the difference?
Thanks anyway, guys. I needed to change it to a do while loop, and change line 18 to char repeat; instead.
Thanks for the info about the iostream though!
Topic archived. No new replies allowed.