Print 1 to N

I can trying create a programme that prints 1 to N. I tried compiling it but i keep getting these errors :
1)[Warning] In function `int main()':

2) parse error before `)' token , line 12

3)parse error before `;' token , line 17

The following is my source code


include<iostream>
using namespace std;

int main(){
double x, y;
cout<<"Enter a number";
cin>>x;
y=1 ;


for(y<=x)
cout<<x <<" ";
y=y+1;


system("PAUSE");
return 0;
}




can someone explain to me whats wrong, thanks
closed account (oN3AqMoL)
In your for loop you didnt include the french brackets around your code.
You did:
1
2
3
for(y<=x)
cout<<c<<" ";
y=y+1;
instead of
1
2
3
for(y<=x){
cout<<c<<" ";
y=y+1;}
closed account (oN3AqMoL)
Plus the for loop isnt complete. I think you meant an if statement?
Last edited on
@qawsed51

This is NOT a for loop
1
2
3
for(y<=x)
cout<<x <<" ";
y=y+1;


This is..
for(y=1;y<x;y++)
If your wanting more than one thing to happen in the loop, enclose them in curly brackets {}, though some programmers use the brackets, even with one statement. Your call.
#1: Missing "#" in line 1. You may have made that mistake with copy and pasting
#2: for ( ; ; ) missing elements

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;

int main() {
  int x;
  cout << "Enter a number ";
  cin >> x;

  for( int y = 0; y < x; y++)
    cout << y + 1 << " ";

  cout << "\n" << endl;
  return 0;
  }
Thanks so much
Topic archived. No new replies allowed.