Okay so I've already finished my code, but was wondering about a certain problem that I'm sure will come up later in my class. What if I wanted my code to loop, but not ask the user if they want to run it again?
So instead of asking, "Would you like to find out another LCM and GCF?"
The code would instead just ask;
"Enter value a: "
"Enter value b: "
Then give the values,
Then again ask
"Enter value a: "
"Enter value b: "
#include <iostream>
usingnamespace std;
int main()
{
int a, b;
int GCF, LCM;
cout << "Enter value a: ";
cin >> a;
cout << "Enter value b: ";
cin >> b;
for (int i = a; i >= 1; i--)
{
if (a % i == 0 && b % i == 0)
{
GCF = i;
break;
}
}
LCM = a * b / GCF;
cout << "The LCM is :" << LCM << endl
<< "The GCF is :" << GCF << endl;
return 0;
}