Im a newb help!

This is a discussion on Im a newb help! within the C++ Programming forums, part of the General Programming Boards category; I am 15 and have been foolin around/ half ..........in with a few compilers. I am taking an actual computer ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    52

    Im a newb help!

    I am 15 and have been foolin around/ half ..........in with a few compilers. I am taking an actual computer programming class next year and I am really interested in it. I was wondering if any of u can help me. I have read a bunch of recommended books and I need help putting them into action.

    I can do really simple basic stuff but I dont know much else.
    If you could help me that would be great. If you have aim u can reach me at DragonSlayerTMO.

    I just need explanation.
    Thanks.

    This is a really simple example of what im trying to do tell me why its not working.
    Code:
    #include <iostream.h>					//this is just a simple
    										//explanation of what it
    int main()								//is that I am trying to do.
    {										//if any could help me that
    	int a;								//would be great!
    		cout << "testing!" << endl;		//Basically I am trying to 
    		cin >> a;						//make it so the program does
    		cout << "testing 2!" << endl;	//both functions...i think thats
    										//the right word anywaz! I cant
    		return a;						//seem to get it to work 
    };										//correctly. Again any help would
    										//be glady appreciated!
    { // this is line 13
    	int b;
    	cout << "testing b!" << endl;
    	cin >> b;
    	cout << "testing b 2!" << endl;
    
    	return 0;
    }
    
    /* Here is the error it gives me.
    On line 13,  error c2447: missing function header*/
    Last edited by Siggy; 06-27-2004 at 06:20 PM.

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Hi there. Some advice. The message board is here for a reason. There's no reason to randomly harass people over AIM.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >If you have aim u can reach me at DragonSlayerTMO.
    You should also check back here because most of us won't bother with AIM, just like we won't bother with email. These forums are for public viewing and if your problem isn't important enough for you to come back to check for replies, it isn't important enough for us to expend effort in helping. Just fair warning.

    >tell me why its not working.
    You can't have code blocks at file scope, there must be a function surrounding your code, for example:
    Code:
    #include <iostream.h>
    
    int f()
    {
      int a;
    
      cout << "testing!" << endl;
      cin >> a;
      cout << "testing 2!" << endl;
    
      return f();
    };
    
    int main()
    {
      int b;
    
      cout << "testing b!" << endl;
      cin >> b;
      cout << "testing b 2!" << endl;
    
      return 0;
    }
    Granted, that's convoluted, but your intentions with the posted code aren't exactly clear.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    52
    Here is another try at it, I made the things more respondable hopefully i can get some help.

    Code:
    #include <iostream.h> 
    int main()
    {
        char a;
        cout << "whats ur name?" << endl;
        cin >> a;
    	cout << a << " is a good name!" << endl;
    	return a;
    };
    int e()
    {
        int b;
        cout << "How old are you?" << endl;
        cin >> b;
        cout << b << " is a good age!" << endl;
        return 0;
    }
    it still doesnt run the second block in the program. All it says is
    whats ur name?
    say that i respond John
    than it says that J(not john for some reason i need ur help on this one) is a good name
    then it ends program
    I need help and im sorry for thinkin i can get help i guess thats too much to ask.
    But then again maybe there are a thousand peope like me so it gets annoying. ANYWAZ i genuinely need help so ill do it according to ur guys "rules"

    pz respond.....

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >it still doesnt run the second block in the program
    Because you don't call the function.

    >than it says that J(not john for some reason i need ur help on this one) is a good name
    Because you only ask for a single character of input.

    Try this:
    Code:
    int main()
    {
      char a[50];
    
      cout << "whats ur name?" << endl;
      cin >> a;
      cout << a << " is a good name!" << endl;
      b();
    
      return 0;
    };
    Just out of curiosity, what "recommended" books have you read, and did you even pay attention while you were reading them? Because both of these problems are a simple and fundamental lack of understanding that the first few chapters of just about any book would alleviate.
    My best code is written with the delete key.

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    If you're interested in computer languages, may I recommend HTML? It's a great language that it's very useful in web programming and will teach you a lot about network architecture.

    (or something...)

  7. #7
    Registered User
    Join Date
    Jun 2004
    Posts
    52
    Lol my browser f'ed up after i had writin like 4 pages of post anywaz here it is in short
    c++ for u ++ (my friend)
    beginning programming for dummies (my dad's colleg's computer instructor)
    3 online guides including this site
    I know a bit of html
    mostly i am just unfamiliar with the terms is why i get confused.

    heres what i have right now
    Code:
    #include <iostream.h> 
    int main()
    {
        char a[50];
        cout << "whats ur name?" << endl;
        cin >> a;
    	cout << a << " is a good name!" << endl;
    	b();                                                                  //LINE 8
    
    	return 0;
    };
    int e()
    {
        int b;
        cout << "How old are you?" << endl;
        cin >> b;
        cout << b << " is a good age!" << endl;
        return 0;
    }
    errors:
    line 8: error C2065: 'b' : undeclared identifier

  8. #8
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Generally function e would be called by something other than b

  9. #9
    Registered User
    Join Date
    Jun 2004
    Posts
    52
    Code:
    #include <iostream.h> 
    int main()
    {
        char a[50];
        cout << "whats ur name?" << endl;
        cin >> a;
    	cout << a << " is a good name!" << endl;
    	e ();
    
    	return 0;
    }
    int e()
    {
        int b;
        cout << "How old are you?" << endl;
        cin >> b;
        cout << b << " is a good age!" << endl;
        return 0;
    }
    ERRORS:
    error C2065: 'e' : undeclared identifier
    (13) : error C2373: 'e' :
    this is the new update

  10. #10
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Put the code of the e() function above main(), or use a prototype above main:
    Code:
    int e();
    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

  11. #11
    Registered User
    Join Date
    Jun 2004
    Posts
    52
    HAAAAH!!!
    I got it workin all thanks to u guys. Wow thanks. That really cleared it all up I think i get the basic structure now. Here is the workin one.
    Code:
     #include <iostream.h> 
    int e();
    int main()
    {
        char a[50];
        cout << "whats ur name?" << endl;
        cin >> a;
    	cout << a << " is a good name!" << endl;
    	e ();
    
    	return 0;
    }
    int e()
    {
        int b;
        cout << "How old are you?" << endl;
        cin >> b;
        cout << b << " is a good age!" << endl;
        return 0;
    }
    Last edited by Siggy; 06-27-2004 at 10:14 PM.

  12. #12
    Registered User
    Join Date
    Aug 2001
    Posts
    22
    sean_mackrory why? Are you are so constructive.

  13. #13
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    >>Siggy

    Make sure that you understand why was your code wrong, why you have to use char[50] instead of char, why you use int e (); before main.
    Understanding why is much more important that just knowing the answer.
    none...

  14. #14
    Registered User
    Join Date
    Jun 2004
    Posts
    20
    getche(); can also be used, if your program ends as soon as the functions are over.

    #include <conio> (on borland)
    #include <conio.c> (on dev and others)

  15. #15
    Registered User
    Join Date
    Jun 2004
    Posts
    20
    Also I think your compiler has examples on this kind a program. Anyway on dev-c++ has this kind of source code.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Question Character Counting
    By Wilder in forum C Programming
    Replies: 13
    Last Post: 06-22-2008, 11:37 PM
  2. Dogpile the newb!
    By lindy in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 05-23-2008, 08:17 AM
  3. Total newb directx invisable geometry question
    By -pete- in forum Game Programming
    Replies: 5
    Last Post: 08-13-2006, 01:45 PM
  4. Newb C++ Programmer
    By Philandrew in forum C++ Programming
    Replies: 8
    Last Post: 10-19-2004, 08:44 PM
  5. if your not newb you can help me
    By Klinerr1 in forum C++ Programming
    Replies: 6
    Last Post: 05-05-2002, 12:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21