whats wrong with it?Code:#include <iostream.h> #include <stdlib.h> int main() { int a, b; cin>>a, b; if(a == /clear) { system("cls"); } elseif(a == /echo) { cin>>b; cout<<"b"; } system("pause"); return 0; }
whats wrong with it?Code:#include <iostream.h> #include <stdlib.h> int main() { int a, b; cin>>a, b; if(a == /clear) { system("cls"); } elseif(a == /echo) { cin>>b; cout<<"b"; } system("pause"); return 0; }
Last edited by Pheonix; 07-23-2003 at 02:10 PM.
What is it you're trying to do with /clear and /echo ?
/clear should clear screen,/echo should just return the text i entered.
my compiler wont compile it because it says: parse error before /
1) You're gonna want to use "/clear" and "/echo". Otherwise your compiler will look for variables named /clear and /echo.
2) The int data type cannot hold a string value.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
dont understand you this is my 1st attempt at c++
Alright, here's some help :
You don't need to do "cin >> b" again, as he's already typed it. If he types anything else than "Echo" or "Clear", the program will quit.Code:#include <iostream.h> #include <stdlib.h> int main() { char a, b; cin >> a, b; // Here, let the guy type in two words if(a == "Clear") // If the word is "Clear" ( case sensitive ) { clrscr(); // then clear the screen } else if(a == "Echo") // Otherwise if he typed "Echo" { cout << "\n" << b; // write out, on the next line, the second word } cout << endl << endl; // Space it out before system("pause"); system("pause"); return 0; }
I think you have to use strcomp() to compare strings not ==.
What about this:
Code:#include < iostream > #include < string > using namespace std; int main() { string a; string b; getline ( cin, a ); getline ( cin, b ); if( a == "/clear" ) { system( "cls" ); } if ( a == "/echo" ) { cout << b << endl; } system( "pause" ); return 0; }
yours bought up 5 errors instead of 1
dev-c++(newest 1(beta))
I see, you were talking about Korhedron's code...Originally posted by Pheonix
yours bought up 5 errors instead of 1
That code won't work because
1. char is used to hold characters - not strings.
2. clrscr(); is exclusive to only a few compilers.
3. Also, like curlious said: "I think you have to use strcomp() to compare strings not ==."
Curlious actually meant to say strcmp() instead of strcomp(), and Curlious probably also meant to say C-strings or character arrays instead of just strings.
The code I posted returned no errors for the Visual C++ compiler.
Last edited by volk; 07-23-2003 at 07:20 PM.
yours bought up 10 errors though
Yes thanks for the corrections just a newbie myself and it was off the top of my feeble head.
It's a bird, it's a plane, no it's super noob; with his big bag 'O errors. If clrscn(); is compiler specific then what would be the Dev-C++ equivilent?
P.S. I also use Dev-C++ (beta), that's why i asked.
"I have read about a hill in a book, so the hill must exist." -a Christian quote
"I have not seen this hill, so it must not exist." -an Athiest quote
"Well, I've heard of this hill, so lets bomb it." -a George Bush quote