A multiplication table where you can enter an integer and enter a range. I'm new to programming and my output came out weird. Like, everything is infinite and it keeps going on and on. Thank You in advance and I apologize for my grammar. I'm not an english speaker.
#include<iostream>
usingnamespace std;
int main() {
int n, range, i;
i = 1;
cout << "Enter an integer: ";
cin >> n;
cout << "Enter range: ";
cin >> range;
do {
int i = 1; i <= range; ++i;
cout << n << " * " << i << " = " << n * i << endl;
} while ( i <= 10 );
return 0;
}
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.
We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
@crispy pata, I assume that you changed your post (to include code) after @Keskiverto's reply. The second link that he/she gave you is very appropriate here.
To make your code work how I suspect it was intended:
- Remove the do and while lines completely; they serve no purpose.
- Change line int i = 1; i <= range; ++i;
to for (int i = 1; i <= range; ++i )
(and you can then remove any mention of i previous to this loop.