+ 2

so this should print variable a up to the value x (wtever u enter) i dont know whats wrong it just prints a++ until it times out

int main() { int x; int a = 1; int b = 2; int c = 3; cin >> x; for(a < x;a++;){ cout << a << endl; } return 0;}

17th Jan 2017, 6:57 AM
jonathin
6 ответов
+ 9
for(; a < x; a++)
17th Jan 2017, 7:01 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 5
this should be: for(; a<x;a++) ie 1) initialisation of counter ( absent in your case) 2)stop condition 3)increment
17th Jan 2017, 7:04 AM
ifl
ifl - avatar
+ 1
#include <iostream> using namespace std; int main() { int x; int a = 1; int b = 2; int c = 3; cin >> x; for(;a <= x;a++){ cout << a << endl; } return 0; }
17th Jan 2017, 7:03 AM
ASNM
ASNM - avatar
+ 1
the for loop must be changed !! it has 1-initialization 2-condition to stop 3-increment/decrement
17th Jan 2017, 9:20 AM
Artur Molla
Artur Molla - avatar
0
I think you wanna the code to print the value of a (I.e 1) for x-times. if am right , modify int main() { int x; int a = 1; int b = 2; int c = 3,k=0; cin >> x; for(;k< x;k++;){ cout << a << endl; } return 0;} and it will print 1 for x-times
17th Jan 2017, 10:42 AM
WONDE-TOM
WONDE-TOM - avatar
0
declare int a,x; and try this loop for(a=1;a<x;a++)
31st Jan 2017, 2:52 PM
sai pranav
sai pranav - avatar