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;
}
Printable View
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;
}
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.
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 :(
What compiler are you using?
dev-c++(newest 1(beta))
I see, you were talking about Korhedron's code...Quote:
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.
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.