Hi,i am a beginner to C++ and have just written a program to get the lowest common multiple. It worked all right but the console/cmd has no response if you input data. If you tell me why it is i would appreciate it.
the code as follows:
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
int n, a[1000];
while (std::cout << "\n Enter number of tries: " && cin >> n)
{
int k = 0;
for (int i = 0; i < n; i++)
{
std::cout << " Enter a[" << i << "]: ";
cin >> a[i];
if (k < a[i])
k = a[i];
}
int i;
do
{
for (i = 0; i < n; i++)
{
if (k % a[i] != 0)
{
std::cout << " In do/while if statement i = " << i << " k = " << k << '\n';
i--;
break;
}
}
k++;
} while (i != n - 1);
cout << k - 1 << endl;
}
return 0;
}
Thank you for your comments. I have just changed the code and it is successful this time. But I have no idea about the difference between those two. it puzzles me.
the new code as follows:
This is where the debugger becomes your new friend. If you use the debugger to trace through the program and monitor the contents of the variables etc, then you'll see what's happening and where the program is deviating from what's expected from the design.
Your code is very helpful.First, I am sorry that I didn't carefully study it before. After having just run it and carefully examined the output, I find my problem .