Thread: super n00b:(

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    12

    super n00b:(

    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?
    Last edited by Pheonix; 07-23-2003 at 02:10 PM.

  2. #2
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    What is it you're trying to do with /clear and /echo ?

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    12

    n00b

    /clear should clear screen,/echo should just return the text i entered.
    my compiler wont compile it because it says: parse error before /

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    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

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    12

    n00b

    dont understand you this is my 1st attempt at c++

  6. #6
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    Alright, here's some help :

    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;
    }
    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.

  7. #7
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    I think you have to use strcomp() to compare strings not ==.

  8. #8
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    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;
    }

  9. #9
    Registered User
    Join Date
    Jul 2003
    Posts
    12
    yours bought up 5 errors instead of 1

  10. #10
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    What compiler are you using?

  11. #11
    Registered User
    Join Date
    Jul 2003
    Posts
    12
    dev-c++(newest 1(beta))

  12. #12
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    Originally posted by Pheonix
    yours bought up 5 errors instead of 1
    I see, you were talking about Korhedron's code...

    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.

  13. #13
    Registered User
    Join Date
    Jul 2003
    Posts
    12
    yours bought up 10 errors though

  14. #14
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    Yes thanks for the corrections just a newbie myself and it was off the top of my feeble head.

  15. #15
    Registered User Ace Bowers's Avatar
    Join Date
    Jul 2003
    Posts
    23
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. n00b questions
    By C+noob in forum C++ Programming
    Replies: 43
    Last Post: 07-09-2005, 03:38 PM
  2. n00b Code Error.
    By Zeusbwr in forum C++ Programming
    Replies: 4
    Last Post: 10-11-2004, 05:15 PM
  3. With super powers would you:
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 09-17-2003, 11:27 PM
  4. Post Super Bowl predictions here!
    By PJYelton in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 01-23-2003, 10:13 PM
  5. Which super hero(ine) are you?
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-15-2002, 06:36 AM