Visual cpp is being screwy

I am 99.9% sure this should be working but it fails. What am I doing wrong?

1>  letcount2.cpp
1>letcount2.cpp(9): error C2144: syntax error : 'int' should be preceded by ';'
1>letcount2.cpp(14): error C2143: syntax error : missing ';' before '<<'
1>letcount2.cpp(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>letcount2.cpp(15): error C2143: syntax error : missing ';' before '>>'
1>letcount2.cpp(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>letcount2.cpp(17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>letcount2.cpp(17): error C2086: 'int x' : redefinition
1>          letcount2.cpp(9) : see declaration of 'x'
1>letcount2.cpp(19): error C2059: syntax error : 'while'
1>letcount2.cpp(19): error C2143: syntax error : missing ';' before '{'
1>letcount2.cpp(19): error C2447: '{' : missing function header (old-style formal list?)
1>letcount2.cpp(24): error C2059: syntax error : 'return'
1>letcount2.cpp(25): error C2059: syntax error : '}'
1>letcount2.cpp(25): error C2143: syntax error : missing ';' before '}'
1>letcount2.cpp(25): error C2059: syntax error : '}'

And my lame program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
int x, y;

	cout << "Lets count! Enter a number to count to... "; //or not
	cin >> x;

	x = 1;
	
	while (x <= y) {
	cout << y << " ";
	y = y + 1;
	}

	return 0;
}
All those errors originated from one, eh? In the end, the only problem with your code besides the three non-errors that I noticed is that line 5 is missing a {.

The non-errors are:
@Line 11: You're rendering line 9 redundant. Delete this line.
@Line 13: You have your variables switched there.
@Line 13: y isn't set to 0 before your loop, which could result in some... odd behavior. Just a precaution.

Happy coding! :)

-Albatross
ugh stupid mistakes around. I made those changes but it instantly closes as soon as I enter a number.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "stdafx.h"
#include <iostream>
using namespace std;


int main(){

//x is input
//y is 1
int x, y;

	cout << "Lets count! Enter a number to count to... "; //or not
	cin >> x;

	y = 1;
	
	while (x <= y) {
	cout << x << " ";
	x = x + 1;
	}
system("pause");//bad I know but cin.get(); isnt working
	return 0;
}
Topic archived. No new replies allowed.