Hello everyone! I'm fairly new to C++ and am having trouble with a "nested loops" problem.
Here is the problem: USING A WHILE LOOP, get integers from the user. Then, USING A FOR LOOP, calculate a 'times table' of that number and the numbers between 1 and 20. When the user enters a zero, end the program. Run the program to see the expected output.
This is the code I've come up with so far...Even though it's "successful," it doesn't even run in my compiler. When entered into the program my professor has created for assignment submissions, it still does a times table for zero, even though I've used the while loop. I've tried collecting the data before the while loop (putting cin >> num just above while (num !=0), and that created an infinite loop.
Please help me with whatever I'm doing wrong! Thanks!
#include <iostream>
using namespace std;
int main ()
{
int num;
while (num != 0)
{
cin >> num;
cout << "times table for " << num << ": " << endl;
for (int x = 1; x <= 17; x++)
{
cout << (num * x) << "\t";
}
cout << endl;
}
}