0

Why doesn't it stop after printing it 20 times ?

#include <iostream> using namespace std; int main () int a; int c = 1; cout << "Please Enter A Number \n"; cin >> a; cout << "Thank you \n"; for (c < 20; c++;) { cout << a * c << endl; }

5th Dec 2016, 9:33 PM
Ash Ketchum
Ash Ketchum - avatar
5 ответов
+ 3
write loop like that for(;c<20;c++) and put a } to terminate the loop
5th Dec 2016, 9:41 PM
Nikhil Dhama
Nikhil Dhama - avatar
+ 2
i think mistake is in for loop for (;c <20;c++) for (initialization; expression; increment/decrement )
5th Dec 2016, 9:42 PM
Vipul Walia
Vipul Walia - avatar
+ 1
Thank you both !
5th Dec 2016, 9:46 PM
Ash Ketchum
Ash Ketchum - avatar
0
Please have a look at for syntax, (initialize; condition; operation)
6th Dec 2016, 2:17 AM
Balaji Kannadassan
Balaji Kannadassan - avatar
0
@Balaji I am aware of how for syntax works, but didn't know that if I declared variable earlier, I needed to put a semicolon as the 'init' and thus, left it blank.
6th Dec 2016, 2:32 AM
Ash Ketchum
Ash Ketchum - avatar