Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Beginner]Visual C++  (Read 2641 times)

0 Members and 1 Guest are viewing this topic.

Jeod

Team Dekunutz, Doubleteam
[Beginner]Visual C++
« on: July 15, 2009, 04:17:48 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1675
This tutorial is basically for people who have never even touched C++ before. First, my notes:


------------------
PROGRAMMING IN c++
VISUAL STUDIO 2008
------------------


=========
VARIABLES
=========

int - Integer 0-9
double - Decimals
char - Single Letter A-Z
string - Word, Phrase, Sentence
bool - True/False

=======
HEADERS
=======

#include<iostream>
#include<VARIABLE NAME>  <--Allows use of variable listed
using namespace std;
int main ()

=====================
EXAMPLE "HELLO WORLD"
=====================

#include<iostream>
using namespace std;
int main ()
{
   cout <<"Hello World!"<<endl;
   system ("Pause");
        return 0;
}

cout is text output. << must be before and after text and text must be in quotes. Endl is endline and a semicolon

must be at the end of every line. System refers to the module that is running the program and ("Pause") causes the system to stop what it is doing. Return 0 causes the system to quit. { and } are open and close keys for the C++ program.

=================
EXAMPLE VARIABLES
=================

cout <<"My lucky number is "<<LuckyNum<<endl;

___________________________ ________________

All above this line is text  This part is the variable <<LuckyNum<<

*So if your number is 7 then the line will read "My lucky number is 7"
**To place a period after your variable simply insert it as <<VARIABLE<<"."<<endl;
***Remember you must have an extra set of carrots if you add a period.

==================
EXAMPLE USER INPUT
==================

        cout <<"What is your favorite number?"<<endl;
   cin>>FavNum;
   cout<<endl;
   cout<<"Your favorite number is "<<FavNum<<"."<<endl;
   system ("Pause");

cin is text input. This line requires the user to type a number. The next line will write the number inputted.

=====
HINTS
=====

cout<<endl; <--This is a space between lines.

= means input operator
== means comparison operator


When you first open Visual C++, you'll need to start a new project. Then you'll need to put in the fundamental headers.

#include<iostream>
using namespace std;
int main();

Remember to put semicolons after namespace std and int main. Some lines need semicolons and some don't. Don't worry about it though; Visual will tell you if you need a semicolon somewhere.

Look at the example "Hello World" and DO NOT COPY AND PASTE IT. Type it out yourself. To test your app, press F5. Visual will compile your program and give you any errors you have at the bottom of the screen.



Notice my error. It's difficult to tell what I did wrong, but when I double click the error it takes me to the open bracket just after int main. This means I did something wrong around here. The error also says "missing function header". The header is int main, so that line is where my problem is. INT MAIN does not need a semicolon. I'll take it out and try running it again, shall I?



Yay! It works! Get used to the DOS box for now; you'll be seeing it a lot.

***Using my notes above, see if you can make a guess the lucky number game. Here's a hint: You'll need two variables. Both are int, and one is luckynumber and the other is luckyinput.
« Last Edit: July 15, 2009, 04:20:55 pm by Jeod »
Logged
"You should challenge your fates. When all else fails, you can still die fighting." ~Yune
___________________________________

Zelda GBC+ Engine for Multimedia Fusion 2
  • Doubleteam Project Page
Re: [Beginner]Visual C++
« Reply #1 on: July 15, 2009, 04:39:54 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
You have several mistakes in this tutorial.  I suggest you fix them before you mislead people =\

Quote
int - Integer 0-9

This is wrong, an int can range from –32768 to 32767.

Quote
double - Decimals

This needs a lot more clarification, like the fact that it has a much larger range than a short int.

Quote
#include<VARIABLE NAME>  <--Allows use of variable listed
...What?  No, this is for including multiple files, not variables.

Quote
=======
HEADERS
=======

#include<iostream>
#include<VARIABLE NAME>  <--Allows use of variable listed
using namespace std;
int main ()

using namespace std and int main() are not headers.  Don't confuse them.  Also, you should go into how the using keyword defeats the purpose of a namespace.  Use std::cout and std::cin instead to resolve the scope.

Quote
string - Word, Phrase, Sentence
I really don't recommend you going into these before even touching arrays in C++.

Quote
= means input operator
== means comparison operator

Explain what these mean, man!  Don't expect people to understand what input and comparison means, this is a beginner tut!

Quote
Return 0 causes the system to quit. { and } are open and close keys for the C++ program.

Return 0 causes the function to exit, not the system.  You just are telling the main function to quit, so it ends the program.  Also, {} are for function definitions NOT the program.

Quote
#include <string>
You don't need this, you're not using the string data type.  The compiler will see your strings as char arrays.

You've got a lot of work to do, Jeod.  You seem to be a beginner yourself with this language.



Logged



i love big weenies and i cannot lie
Re: [Beginner]Visual C++
« Reply #2 on: July 15, 2009, 04:41:06 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
*whistles* There are a lot of misinterpretations and half-truths in that. I'm not even sure where to start on them D:.

EDIT:

Quote
This is wrong, an int can range from –32768 to 32767.
Your refering to a short or int16. Integers in C++ are 4 bytes long (hence 32bit operating system), their range (if signed) is –2147483648 to 2147483647.
« Last Edit: July 15, 2009, 04:43:12 pm by Infini »
Logged
Re: [Beginner]Visual C++
« Reply #3 on: July 15, 2009, 04:44:28 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Whoops, my bad, pulled up the wrong value >_>
Logged



i love big weenies and i cannot lie
Re: [Beginner]Visual C++
« Reply #4 on: July 15, 2009, 04:52:24 pm »
  • Fight the Power
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1245
That sums it up pretty well imo. :P Although it might not be suitable for someone who has never programmed before in his life and doesn't have a clue what he's doing. Maybe explaining what a variable is, for instance, might help.
But! since most of the people here have programmed in at least Game Maker, I think it's easy enough to understand.

Oh and one thing, didn't you forget to add the #include<stdafx.h>? Or something like that.

Oh and, are we supposed to try our hands at this? :P
Quote
***Using my notes above, see if you can make a guess the lucky number game. Here's a hint: You'll need two variables. Both are int, and one is luckynumber and the other is luckyinput.

In that case,

Code: [Select]
#include<iostream>
#include<stdafx.hsomething>
using namespace std;

int luckynumb()
{
cout << "Try to guess the lucky number! >:O" << endl;
cin >> luckyinput;
}

int main()
{
int luckynumber = "5"

int luckynumb();

switch (luckyinput)
   {
  
   case(5):
   cout << "Congratulations! You've guessed the lucky number! :D" << endl;
   break;

   default:
   cout << "Nope! That's not it, try again.
   luckynumb()
   break;
  
   }

}


Quickie, is it right? :P

You didn't explain anything about the if, else and switch statements though. :P

Other than that, great tutorial! :)

EDIT: Now that I think about it, I really don't understand why you added the #include<VARIABLE NAME> :S that AND the #include<String>
« Last Edit: July 15, 2009, 04:57:18 pm by Darunia »
Logged

Currently Listening to: Mos Def - Summertime
Re: [Beginner]Visual C++
« Reply #5 on: July 15, 2009, 04:56:00 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Quote
Oh and one thing, didn't you forget to add the #include<stdafx.h>? Or something like that.
Thats only needed if your using a precompiled header in VS.
Logged
Re: [Beginner]Visual C++
« Reply #6 on: July 15, 2009, 04:59:58 pm »
  • Fight the Power
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1245
Quote
Oh and one thing, didn't you forget to add the #include<stdafx.h>? Or something like that.
Thats only needed if your using a precompiled header in VS.
Well for somebody completly new, it must be mentioned. If you create a new file and don't add this it returns an error, at least for me :S. I know you only need this on VS though.
Logged

Currently Listening to: Mos Def - Summertime

Jeod

Team Dekunutz, Doubleteam
Re: [Beginner]Visual C++
« Reply #7 on: July 15, 2009, 05:39:24 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1675
I have much more notes than that. I'm currently in class and that's why I didn't take time to check my notes. Thanks for the clarifications MG, they helped a bit. I do have Arrays in my notes, that's why the string is there.

I am a beginner, that's why I'm writing this as I go. I figured better to teach others as you go, instead of waiting until you know a bunch of stuff. Because then you tend to assume the beginners will know what you're talking about.

Darunia:

I got many errors in your code. Here is a modified version in which there is only one error:

Quote
#include<iostream>
using namespace std;

int luckynumb();
int luckyinput;
int main()
{
cout << "Try to guess the lucky number! >:O" << endl;
cin >> luckyinput;

int luckynumber = "5";

int luckynumb();

switch (luckyinput)
   {
  
   case(5):
   cout << "Congratulations! You've guessed the lucky number! :D" << endl;
   break;

   default:
   cout << "Nope! That's not it, try again.";
   luckynumb();
   break;
  
   }

}

Are you using Microsoft Visual C++?  The only error I have in it is 'cannot convert from constant char [2] to int'. Perhaps MG or Infini can help you out. Each programmer codes a different way, and I haven't learned switch and case yet.

I also know why stdafx.h is needed for you and not me. When creating a new project, I check *empty project* in console options.

***And here is a dump of all my notes as of now.

Quote
------------------
PROGRAMMING IN c++
VISUAL STUDIO 2008
------------------


=========
VARIABLES
=========

int - Integer 0-9
double - Decimals
char - Single Letter A-Z
string - Word, Phrase, Sentence
bool - True/False

=======
HEADERS
=======

#include<iostream>
#include<VARIABLE NAME>  <--Allows use of variable listed
using namespace std;
int main ()

=====================
EXAMPLE "HELLO WORLD"
=====================

#include<iostream>
using namespace std;
int main ()
{
   cout <<"Hello World!"<<endl;
   system ("Pause");
        return 0;
}

cout is text output. << must be before and after text and text must be in quotes. Endl is endline and a semicolon must be at the end of every line. System refers to the module that is running the program and ("Pause") causes the system to stop what it is doing. Return 0 causes the system to quit. { and } are open and close keys for the C++ program.

=================
EXAMPLE VARIABLES
=================

cout <<"My lucky number is "<<LuckyNum<<endl;

___________________________ ________________

All above this line is text  This part is the variable <<LuckyNum<<

*So if your number is 7 then the line will read "My lucky number is 7"
**To place a period after your variable simply insert it as <<VARIABLE<<"."<<endl;
***Remember you must have an extra set of carrots if you add a period.

==================
EXAMPLE USER INPUT
==================

        cout <<"What is your favorite number?"<<endl;
   cin>>FavNum;
   cout<<endl;
   cout<<"Your favorite number is "<<FavNum<<"."<<endl;
   system ("Pause");

cin is text input. This line requires the user to type a number. The next line will write the number inputted.

=====
HINTS
=====

cout<<endl; <--This is a space between lines.

= means input operator
== means comparison operator

==========
Conditions
==========

if (If input is A...)
else if (If input is A OR S...)
else (If input is neither A or S...)
while (continuous)

======
ARRAYS
======

int
char
double
string

EXAMPLE INT ARRAY

int scores (Has several scores)

int scores[5] (Can store 5 different numbers)

int scores[5] = {85, 64, 23, 95, 100};

cout<<scores[1]; (Number is 64 because slots go from 0-4)

int scores[5];
scores[0] = 85
scores[1] = 64
scores[2] = 23
scores[3] = 95
scores[4] = 100

===========================
OBJECT ORIENTED PROGRAMMING
===========================



==============
INPUT CHECKING
==============

   cout<<"Please enter a number."<<endl;
   cin>>num1;
   while (cin.fail())
   {
   cout<<"Enter a number, fool."<<endl;
   cin.clear();
   cin>>dummy;
   cin>>num1;
   }

**Need a dummy value to store old data.
**cin.clear clears the old data.

====
VOID
====

void - a storage space for code that can be called on later.

EXAMPLE

void Example()

Example()

=====
SLEEP
=====

#include<windows.h> <- Sleep is a Windows function
#include<dos.h>
#include<time.h>

*Sleep must be capitalized

Sleep(200) <- 200 milliseconds = 2 seconds

======
REFLEX
======

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

void Reflex()
{
   srand (time(NULL));
   while(1)
   {
   random = rand() % 5000 + 1000;
   Sleep(random);
   cout<<"Quick! Press a button!"<<endl;
   
   int counter = 0;
   while (!_kbhit())
   {
      
   Sleep(1);
      
   counter++;
   }
   getch();  <- This clears the kbhit. Don't ask why you need it, you just do.
if (counter < 100)
{
   cout<<endl;
   cout<<"Reflex accepted. The fifth letter of the password is R."<<endl;
   cout<<endl;
   break;
}
else
{
   cout<<endl;
   cout<<"Denied. You were too slow. Resetting console..."<<endl;
   cout<<endl;
}
}
}
« Last Edit: July 15, 2009, 06:00:12 pm by Jeod »
Logged
"You should challenge your fates. When all else fails, you can still die fighting." ~Yune
___________________________________

Zelda GBC+ Engine for Multimedia Fusion 2
  • Doubleteam Project Page
Re: [Beginner]Visual C++
« Reply #8 on: July 15, 2009, 07:27:59 pm »
  • (y)(;>.<;)(y)
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3293
Quote
#include<iostream>
using namespace std;

int luckynumb();
int luckyinput;
int main()
{
cout << "Try to guess the lucky number! >:O" << endl;
cin >> luckyinput;

int luckynumber = "5";// here you're assigning a string to an integer, if you don't wanna do this (you don't) don't need the speech marks

int luckynumb(); // eh?

switch (luckyinput)
   {
  
   case(5):
   cout << "Congratulations! You've guessed the lucky number! Cheesy" << endl;
   break;

   default:
   cout << "Nope! That's not it, try again.";
   luckynumb();
   break;
   }

}
Logged
Re: [Beginner]Visual C++
« Reply #9 on: July 15, 2009, 07:56:56 pm »
  • Fight the Power
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1245
Quote
int luckynumb();
Oops. Ahahaha, now that I look back at it I made a lot of mistakes. :D

Jeod, switch is a function that works like if you were using If and Else If statements.

Switch ( Your variable goes here. )
{
case ( Variable's value. ):
Do something.
break;

default:
If none of the above fit, do this.
break;
}

Got it? :)

Also,

Quote
int luckynumber = "5";// here you're assigning a string to an integer, if you don't wanna do this (you don't) don't need the speech marks
Thanks TDJ, didn't know that. :D

Quote
I am a beginner, that's why I'm writing this as I go. I figured better to teach others as you go, instead of waiting until you know a bunch of stuff. Because then you tend to assume the beginners will know what you're talking about.

That's a good point, but make sure you know exactly what you're talking about before you try explaining it to others. :]
« Last Edit: July 15, 2009, 07:59:43 pm by Darunia »
Logged

Currently Listening to: Mos Def - Summertime
Re: [Beginner]Visual C++
« Reply #10 on: July 15, 2009, 08:11:17 pm »
  • (y)(;>.<;)(y)
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3293
If you were to ask me the world doesn't need another beginners tutorial in C++ anyway, they are plenty out there and they're all about the same really.

What the world really needs is more advanced lessons...if you wanna learn graphics they are again more than enough good tutorials on the subject.

What does the world need then? Well, quite simply in my own opinion the world needs more tutorials, example and information on Game engine design and creation. Okay, perhaps Tutorial is a bit too far. More like a "Series of online lectures followed by question and answer sections". They are so many different ways of getting collision, render, input, audio and logic to all work together it can be very mind boggling to people who are just stepping into it beyond the very simple level.

That was the kind of thing that ZFGC University idea would have been perfect for...
Logged
Re: [Beginner]Visual C++
« Reply #11 on: July 15, 2009, 08:23:17 pm »
  • Fight the Power
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1245
I think he's just doing it for practice rather than to help the others learn, tight butthole.
This kind of 'resumé' can help you test your knowledge and see if you really know what you're talking about.

Btw, if you're intersted Jeod, the tutorials over at www.learncpp.com are really awesome, they treat you like a complete beginner. I've been using those, they're extremely useful! :D
Logged

Currently Listening to: Mos Def - Summertime

Jeod

Team Dekunutz, Doubleteam
Re: [Beginner]Visual C++
« Reply #12 on: July 15, 2009, 08:26:16 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1675
Sweet, I'll do it. But not until I finish my class first ;)
Logged
"You should challenge your fates. When all else fails, you can still die fighting." ~Yune
___________________________________

Zelda GBC+ Engine for Multimedia Fusion 2
  • Doubleteam Project Page
Re: [Beginner]Visual C++
« Reply #13 on: July 15, 2009, 11:10:25 pm »
  • (y)(;>.<;)(y)
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3293
Trust me, nothing beats the god-complex-rush you get from knowing more than the level you're being taught at and your peers in the class ^^
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.066 seconds with 65 queries.

anything