|
-
May 16th, 2005, 04:45 PM
#1
Thread Starter
Admodistrator
Whats wrong with this code?
Code:
#include <iostream>
using namespace std;
int main()
cint >> x;
{
switch (x) {;
Case 1:
cout << "X = 1";
Case 2:
Cout << "x=2";
Case 3:
cout << "x =3";
Case else
cout << "x =";
cout << n;
}
system( "pause" )
return 0;
}
i get this:
ompiling...
Cpp1.cpp
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(6) : error C2146: syntax error : missing ';' before identifier 'cint'
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(6) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Cpp1.exe - 2 error(s), 0 warning(s)
-
May 16th, 2005, 04:48 PM
#2
Not NoteMe
Re: Whats wrong with this code?
Its before the opening '{' following the 'main' function. Plus i think you want 'cin' not 'cint'
Don't forget that with a case statement, the code will run all code from the first matching case statement. For example if x is 1 it'll run all of the case statements.
Use the 'break' keyword to get out of the switch statement after you've done stuff specific to that case.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
May 16th, 2005, 04:57 PM
#3
Thread Starter
Admodistrator
Re: Whats wrong with this code?
Code:
#include <iostream> //<iostream.h> is deprecated
using namespace std;
int main()
cin >> x;
{
switch (x) {;
Case 1:
cout << "X = 1";
break;
Case 2:
Cout << "x=2";
break;
Case 3:
cout << "x =3";
break;
Case else
cout << "x =";
cout << n;
break;
}
system( "pause" )
return 0;
}
thanks for the break, but can you explain this, or show me how youd do it:
ts before the opening '{' following the 'main' function. Plus i think you want 'cin' not 'cint'
-
May 16th, 2005, 05:35 PM
#4
Re: Whats wrong with this code?
C++ is case-sensitive. You must write "case".
Code:
int main()
cin >> x;
{
You've got the order of the lines mixed up here. The "{" should be before the "cin >> x;"
This semicolon is misplaced.
"case else" doesn't exist. It's called "default" and needs a colon like all the case marks.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 16th, 2005, 05:42 PM
#5
Thread Starter
Admodistrator
Re: Whats wrong with this code?
thanks, (case else = vb )
Code:
#include <iostream> //<iostream.h> is deprecated
using namespace std;
int main();
{
cin >> x;
switch(x){ ;
Case 1:
cout << "X = 1";
break;
Case 2:
Cout << "x=2";
break;
Case 3:
cout << "x =3";
break;
default;
cout << "x =";
cout << n;
break;
}
system( "pause" )
return 0;
}
Code:
Compiling...
Cpp1.cpp
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(6) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.
-
May 16th, 2005, 06:08 PM
#6
Re: Whats wrong with this code?
You didn't remove the semicolon as I told you, and there's another wrong one at the end of the main() line.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 16th, 2005, 06:10 PM
#7
Thread Starter
Admodistrator
Re: Whats wrong with this code?
Code:
#include <iostream> //<iostream.h> is deprecated
using namespace std;
int main()
{
cin >> x;
switch(x){
Case 1:
cout << "X = 1";
break;
Case 2:
Cout << "x=2";
break;
Case 3:
cout << "x =3";
break;
default;
cout << "x =";
cout << n;
break;
}
system( "pause" );
return 0;
}
Compiling...
Cpp1.cpp
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(7) : error C2065: 'x' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(10) : error C2065: 'Case' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(10) : error C2143: syntax error : missing ';' before 'constant'
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(10) : error C2143: syntax error : missing ';' before ':'
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(13) : error C2143: syntax error : missing ';' before 'constant'
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(13) : error C2143: syntax error : missing ';' before ':'
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(16) : error C2143: syntax error : missing ';' before 'constant'
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(16) : error C2143: syntax error : missing ';' before ':'
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(19) : error C2143: syntax error : missing ':' before ';'
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(21) : error C2065: 'n' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(23) : warning C4065: switch statement contains 'default' but no 'case' labels
Cpp1.exe - 10 error(s), 1 warning(s)
-
May 16th, 2005, 06:19 PM
#8
Re: Whats wrong with this code?
'x' : undeclared identifier
Ever seen what happens when you enable Option Strict in VB?
'Case' : undeclared identifier
It's a matter of case. (BTW, that's the second time I need to tell you this.)
All C2143 errors are follow-ups.
'n' : undeclared identifier
Big surprise, when you called the variable 'x' earlier.
I think you need to unlearn VB before you can learn C++. I also think you need to learn to read the answers to your questions and apply what is in there - everything, not just a single thing.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 16th, 2005, 06:28 PM
#9
Thread Starter
Admodistrator
Re: Whats wrong with this code?
im sorry, didnt see this part at all
C++ is case-sensitive. You must write "case".
ill stop buggin you, you seem really angry/ornery...
-
May 16th, 2005, 07:34 PM
#10
Fanatic Member
Re: Whats wrong with this code?
Sample code directed by CornedBee.
VB Code:
#include <iostream>
using namespace std;
int main(){
int x; // declare x first
cin>>x;
switch(x){
case 1: // case not Case
cout<<"x = 1";
break;
case 2:
cout<<"x = 2";
break;
case 3:
cout<<"x = 3";
break;
default:
cout<<"x = ";
cout<<x; // not n coz we're dealing with x
}
cout<<endl;
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|