Need help with first program!


Hello, first post, hope im doing it at the right place!

Super new at c++.

I just made a program all by myself (Still in the works) and wanted to see if im doing everything in the best way.

So i wanted to see if anyone could look at the code, and tell me all of your comments. Anything is helpful! (Im 14, so give meh some slack ;) )


http://www.filedropper.com/firstprogram

^^Download link^^

Thanks again!!
just post the code here i dont download stuff =x
Pretty good for a first program :)

I have 2 suggestions however:

1. Make your conditional statements more readable (and easier to type)
1
2
3
4
5
6
7
8
9
if (Q4==3)
//right

if (Q4!=3)
//wrong

//the 2nd could be changed to:
else
//wrong 

This isn't an issue, but I thought I'd let you know.

2. Reuse variables
1
2
3
int Q1, Q2, Q3, Q4, Q5, Q6;
//could be:
int ans;

Again, not exactly an issue, however, this will make your program more memory efficient. Once you start making bigger, more complex programs, memory efficiency is key.
Yah that would be smart... lol...

#include <iostream>

int main(){
using namespace std;




int Q1, Q2, Q4, Q5, Q6;
char Int1, Int2;





cout << "Hello, and welcome to the Blue Sun RTS test!" << endl << endl << endl << endl;
cout << "Would you like to start the test now?" << endl;
cout << "1): Yes" << endl;
cin >> Q1;

if(Q1 == 1){
cout << endl << "Perfect! I will now start asking some basic infomation." << endl;
cout << "How old are you?" << endl << "Enter age: " << endl;
cin >> Q2; //Q2

if(Q2 >= 13){
cout << endl << "And what is your first initial?" << endl;
cin >> Int1; //Int 1
cout << endl << "Thank you. And your second?" << endl;
cin >> Int2; //Int 2
cout << endl << "Very good. Welcome " << Int1 << Int2 << " to the Blue sun RTS test." << endl << endl;
cout << "This test was made to see how intellegent some people are." << endl << endl;
cout << "Are you ready to start?" << endl;
cout << "(Please keep in mind that if you get a question wrong, you will have to restart.)";
cout << "1): Yes" << endl;
cin >> Q4; //Q4
}


if(Q2 < 13){
cout << "Sorry, you cannot take this test." << endl; //If age is not greater (Or equal) to 14.
system("pause");



}



}

cout << endl << "Very good! Lets start." << endl;
cout << endl << "Question 1. What color is the ocean?" << endl;
cout << "1): Red" << endl << "2): Orange" << endl << "3): Blue" << endl << "4): Purple" << endl;
cin >> Q4; //Q4

if(Q4 == 3){
cout << "Very good!" << endl << endl;
}
if(Q4 != 3){
cout << "Im sorry, you are wrong. Please restart the program and try again. Thank you." << endl << endl;
cin.get();
}

cout << "Question 2. What is 10 - 5?" << endl;
cin >> Q5; //Q5

if(Q5 == 5){
cout << "Very good!" << endl << endl;
}
if(Q5 != 5){
cout << "Im sorry, you are wrong. Please restart the program and try again. Thank you" << endl;
cin.get();
}

cout << "Question 3: What is 5 x 3?";
cin >> Q6;

if(Q6 == 15){
cout << "Very good!";
}
if(Q6 != 15){
cout << "Im sorry, you are wrong. Please restart the program and try again. Thank you" << endl;
cin.get();
}



system("pause");
return 0;



}
Gah that was fast O.o

Yah i was looking how to make it easier to read, thx!

Any way i can make it less code?
You could break it up into separate functions, and perhaps have a universal question function that takes several string parameters and some int's so that asking the user a question from main() would be as small as:
1
2
3
4
5
6
7
8
int anser = 2;
bool correct;

correct = AskQ("Question", "ans1", "ans2", "ans3", "ans4", answer);

if (!correct){
handle_error();
exit(0);}

However, I think that would be overkill. =)
I think your code is fine as it is now for your first project.
Last edited on
Oh ok, very cool.

Where should of program/ what should i learn next?

I really want to go into making games. So what would be my best move? I have looked at some video game code, and nothing look's like what im doing.

Thx again !!! =)
So you want to make games huh? Game programming is by far my favorite kind of
programming :)

First, you'll need to find a good game library that can be used to get user input, draw to the screen, play sounds, multi-threading support, etc. I would suggest Allegro or SDL for this. Then, just play around and get familiar with all the different features of your library of choice. From there, start with some basic games (mazes, pong, etc) then move up as you gain more experience.

Here are some links:
SDL:
Download: http://lazyfoo.net/SDL_tutorials/lesson01/windows/msvsnet2010e/index.php
Tutorial: http://lazyfoo.net/SDL_tutorials/index.php

Allegro:
Download: http://www.allegro.cc/files/
Tutorial: http://www.cppgameprogramming.com/cgi/nav.cgi?page=index

Just PM me if you need any help or if you want any games :)
cout << "This test was made to see how intellegent some people are." << endl << endl;

1
2
cout << endl << "Question 1. What color is the ocean?" << endl;
cout << "1): Red" << endl << "2): Orange" << endl << "3): Blue" << endl << "4): Purple" << endl;


The ocean is not blue, just thought I'd point that out.
Where i live it is!

And thx again Mod!!!!

Just i tried SDL for MS 2008 and 2010 VB C++ and it did not work. It twas weird....

As for allergo, what download link would be VB 2010 or 2008? I really only like vb... Dont really like the other complier's (If thats what there called);

Thx again!

Oh it didn't let me PM you for some reason?
Last edited on

First, you'll need to find a good game library that can be used to get user input, draw to the screen, play sounds, multi-threading support, etc. I would suggest Allegro or SDL for this. Then, just play around and get familiar with all the different features of your library of choice. From there, start with some basic games (mazes, pong, etc) then move up as you gain more experience.



Woah!! You should NOT jump straight into game developing like that. Before you even consider using an external library, you should at least have very good knowledge of the standard c++ library. You should have advanced knowledge of OOP and you should have at least 2 or 3 Text based games under your belt. Here is a list of the basics that you should understand inside and out:
I/O
variables
program flow
templates
classes
inheritance etc.


Jumping straight into graphical programming, and trying to run before you can walk, as they say, will only hurt you in the long run. OOP, memory allocation, effiency of code, basic code structure, are not things you wan't to think about while writing a game. They should be hardcoded into your head, so you don't need to think about them. Until you have those most basic of requirements, I don't suggest you should even look at graphical game programming.

I realise you may already realise this, but this reply was based on what ModShop had posted, I just didn't think it was the best advice from him/her.
Last edited on
@dAND3h:
I agree with part of your post. Variables, program flow, code structure and I/O should be learned well before attempting graphics, however, OOP can be learned along side graphics programming. Graphical programming is not at all harder than the console (with most libs anyways) and won't get in the way of learning the language.
Ya i knew that from day 1 :(

Just video game was around me my whole life, and just want to see how it works :P

So i was going to try to learn how to walk... and see people run!

I just dont know where to go to from ^^^^^^ that code i posted. Ik how to do variables (i think).. and all the guides i see doesn't ACTUALLY show you how to do it/what to write. Not what all the things actually do.

And i do not want to wait till 11th grade to learn it (9th now).

Thx both for help!
I'm in 9th too actually. Have you looked at the tutorials on this site? They are where I learned from.

EDIT: Try changing your settings to allow private messages
Last edited on
Nope didnt work for the PM :(

So where do you think i should learn next from what you say in the program? Im still going to look into video game programming atm, and work up. Or if you really think so i could try to learn it now.

All up to you, i've tried to find out what to learn, and its been a failure...

And thx so much for all help!!1
Well, if I were you, I would read through the tutorials on this site and do all the examples. Make sure you understand them. Then choose a game lib and do the tutorials for the one you choose. You should also attempt small projects along the way as well, to keep your skills fresh. Then, start making games. Whatever you don't/can't figure out, you'll eventually learn when you actually need it.

email me at: invince24@earthlink.net
if you need any help.

Also: http://cplusplus.com/forum/articles/12974/
Last edited on
excuse me for butting in, but this just goes to further prove my point that almost ALL new c++ programmers want to get into game development. im not saying its a bad thing, cause it really isnt, but i still dont understand why...?

also check out ModShop's new fancy dancy game development article which should help you out some :0
http://cplusplus.com/forum/articles/42474/
Last edited on
Haha, thanks! I bet you can't guess who else here started programing for games. Although, I have expanded into other areas and find many aspects of computer science very interesting.
Topic archived. No new replies allowed.