1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

My little C++ programs

Discussion in 'Miscellaneous' started by laurentiu, Oct 11, 2011.

Mods: BlueLuigi
  1. laurentiu

    laurentiu Ballista Bolt Thrower

    Messages:
    340
    Hey guys, I`ve started reading Programming Principles and Practice using C++ book. And I have already learned some interesting stuff, here is my first little program thingy, besides the Hello, World one :). Don`t worry, I won`t give you fake programs that shut down your PC etc, it`s safe.
    I am hoping of starting to make a little game something, it would be with zombies, mostly like a 2d zombie survival game, but no promises, I am just at the beggining.

    -Name and age(This program asks you to input your name and age, what it does with your age is just a little bonus ;)). Link: http://www.megaupload.com/?d=LTHH013A
     
  2. Chosen

    Chosen Shopkeep Stealer

    Messages:
    156
    Hello, Laurentiu. It seems that you have started with C++. So did I.

    However, when you start programming, you need to do two things...
    1. Learn to 'program' (solve problems efficiently).
    2. Learn your language of choice.
    C++ is a great language for point 1, however, the language itself is very, very strict and rather hard. And learning to 'program' often needs that one thinks outside the box, learns to just try stuff, etc....
    I personally found it hard to have to learn both things at the same time. However, please don't feel unnecessarily discouraged, however, I would like to give one piece of advice:
    If you don't succeed at first, it often helps for me to just leave it for a few hours or days.
    Best of luck, Chosen, an amateur programmer in C++, and aspirant-programmer in Python (I can't seem to find good tutorials for it). Hope this helps :)
     
  3. laurentiu

    laurentiu Ballista Bolt Thrower

    Messages:
    340
    It`s a bit hard indeed but I found it fun and interesting. Now, I am working on the registration part of the game...I am sure I don`t do it as I should but do you, or anyone, have an idea of how could I allow ints and strings into an input too?

    I mean for the password part I have this:
    Code:
        cout<<"Ok,"<<name<<".Now choose a security code so that only you can access your account!\n";
        int password;
        cin>>password;
        cout<<"Ok, make sure no one is around...\n";
        Sleep(5000);
        cout<<"Done?Good, your password is"<<password<<",dont forget it!\n";
    As int expects only numeric characters(1,2,3 etc.), if you input a word or a word and some numeric characters, the last line of the code will display -1 as your password.

    Basically I need a way to let the definition accept both int and string characters.
     
  4. SirSalami

    SirSalami THD Team THD Team Administrator

    Messages:
    301
    Congrats laurentiu!

    Also, strings can have numbers in them as well as letters!
     
  5. Shadlington

    Shadlington THD Team THD Team Administrator Global Moderator

    Messages:
    1,562
    Hrm. You seem to be skipping over some fundamental concepts a little too fast there laurentiu.
    You need to walk before you can run.
    You should try to get a firmer grasp on data types, for starters.

    But as far as your question goes, why do you need it in an int? It looks like all you want the password for is printing to the output again. If you don't intend to do any arithmetic with the numbers you'll be fine keeping them in a string.
    However, if you really need it then you're not looking for a way to have a variable accept both an int and a string, you're looking for a way to convert a string of numbers into an int. For that you may want to read up on the atoi function.
     
  6. laurentiu

    laurentiu Ballista Bolt Thrower

    Messages:
    340
    Well, my initial plan is to make this a registration form, obviously I am not good at it, and then make some sort of login form so that users can log in with the name and password they have chosen.
     
  7. Shadlington

    Shadlington THD Team THD Team Administrator Global Moderator

    Messages:
    1,562
    Trust me, you do not want to jump straight into any big projects.
    Anything you write now you are going to think is utter crap a few months down the line when you have a better grasp of what you're doing.
     
    Chosen likes this.
  8. laurentiu

    laurentiu Ballista Bolt Thrower

    Messages:
    340
    Well, I already believe it`s crap... :\
     
  9. incarnum

    incarnum Shopkeep Stealer

    Messages:
    35
    Hello laurentiu, I'm glad you're jumping into the world I live in everyday.

    String data type accepts integers as well. You should probably read something about core concepts/basics, something like the (in)famous learn x in 21 days (where x is your programming language of choice). I believe one of those would get you started, just make sure they're up to date as various things in them might be deprecated and/or invalid.
     
Mods: BlueLuigi