First c++ code

Posts 1–9 of 9 · Page 1 of 1
First c++ code
Could you comment on how i could improve my C++ please?

Code:
#include "stdafx.h"
#include <iostream>
 
using namespace std;
 
int main()
{
        cout << "2" << endl;                                    //tells you the number that is asked for below
        cout << "What number did i tell you?" << endl;          //asks number stated above
        int f;                                                  //declares f
        cin >> f;                                               //gives f a value that you enter
        if(f == 2)
        {
                cout << "Succes!" << endl;                      //prints "Succes!" if answered correctly
        }

		
		else
		{	
			cout << "Game over!" <<endl;	        //prints "Game over!" if answered incorrectly

		}

 
       
}
Ohhai nugga

No return statement(add return 1; at the end of the main function)
Indention around the else is f*cked =p

Other then that great first program =^.^=
You included stdafx header, twice, just needed once.

Edit: you beat me to it
Good first progam Only add retun 0;
And you should make a for loop that keeps saying a number to guess till you got the good number.
I was planing to create a new topic but i will continiune to this one...

im new in C++ (i was working on Pascal/Visual Pascal/Delphi) and due to im not person that can learn something by reading a book, i need your help.

so i have some questions.

1st:
For what are inclusions for
[# include "file.h"] or [# include <something>]

2nd:
What is "using namespace"

If you have some "example" codes like this i would appreciate it if you could upload them and explain me some things


Thank you in advanve
THeLE GR
Quote Originally Posted by thelegr View Post
I was planing to create a new topic but i will continiune to this one...

im new in C++ (i was working on Pascal/Visual Pascal/Delphi) and due to im not person that can learn something by reading a book, i need your help.

so i have some questions.

1st:
For what are inclusions for
[# include "file.h"] or [# include <something>]

2nd:
What is "using namespace"

If you have some "example" codes like this i would appreciate it if you could upload them and explain me some things


Thank you in advanve
THeLE GR
well idk how to teach others that's why I'm going to tell you what I have in my head right now....(Well im mad)...

the f*cking #include "something", is used ti include a header from your current project, and the f*cking #include <something>, is used to include a file/header from the 'include' folder...(Well idk how to explain the include folder =P)

You can include a file which isn't actually on your project...
Code:
#include <Windows.h> //My favorite tehe
That gay f*cking using namespace <name>, is used to import a namespace into your project/file. Well it's like the Import function in visual basic....So for ie:
when you use this shit:
Code:
using namespace std; //in iostream btw ;)
will save you time, and then is unneeded to put for ie:
Code:
std::cout << "Play&Win\n";
but only:
Code:
cout << "Play&Win\n";
Hope you did understand my fancy post =P
Quote Originally Posted by thelegr View Post
I was planing to create a new topic but i will continiune to this one...

im new in C++ (i was working on Pascal/Visual Pascal/Delphi) and due to im not person that can learn something by reading a book, i need your help.

so i have some questions.

1st:
For what are inclusions for
[# include "file.h"] or [# include <something>]

2nd:
What is "using namespace"

If you have some "example" codes like this i would appreciate it if you could upload them and explain me some things


Thank you in advanve
THeLE GR
1st: Both, "file.h" are header files and <something> are libs in your compiler.

2nd: if you dont use that you have to typ the hole time std::
Quote Originally Posted by skulhead View Post
1st: Both, "file.h" are header files and <something> are libs in your compiler.

2nd: if you dont use that you have to typ the hole time std::
I thought that to imports lib's is used:
Code:
#pragma comment(lib, "libname.lib")
Quote Originally Posted by user590177 View Post


well idk how to teach others that's why I'm going to tell you what I have in my head right now....(Well im mad)...

the f*cking #include "something", is used ti include a header from your current project, and the f*cking #include <something>, is used to include a file/header from the 'include' folder...(Well idk how to explain the include folder =P)

You can include a file which isn't actually on your project...
Code:
#include <Windows.h> //My favorite tehe
That gay f*cking using namespace <name>, is used to import a namespace into your project/file. Well it's like the Import function in visual basic....So for ie:
when you use this shit:
Code:
using namespace std; //in iostream btw ;)
will save you time, and then is unneeded to put for ie:
Code:
std::cout << "Play&Win\n";
but only:
Code:
cout << "Play&Win\n";
Hope you did understand my fancy post =P
Hehe... I realy enjoyed your post :P
---------------------------------------
Thank you guys!

Ill try to make a small code based on this code
Posts 1–9 of 9 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us