PDA

View Full Version : Beginner programming question


careem
06-11-2004, 06:36 PM
undefinedi'm very interested in coding and how to programme but i want to start with a damn simple question,,,,

how to
1. add 2 value such as value a and b with the programme ask your name, she will say 'I will add your two value..please enter first value ...<a value> and enter second value..<b value>'???.
2. what is the #include <stdio> is, can someone please tell me...is there anything other than is and what it is for???

thanx...

Jason
06-11-2004, 08:08 PM
#include is for including different libraries or files containing functions that you have written. STDIO stands for the standard input/output and will use the cin/cout functions.

int a, b;
cout << "What is the first number?";
cin >> a;
cout << "What is the second number?";
cin >> b;
cout << "a + b = " << a+b ;


something like that...


Jason

Serex
06-11-2004, 11:14 PM
ok for jasons example you will need to #include "iostream". this basically tells the program that you wanna chose from a library of functions that contain cin and cout.

the stdio header, if im correct is just another library of i/o functions. you can rightclick on "stdio.h" and open it within VS (if you use that). it will give u a list of what is contained within.

careem
06-14-2004, 07:09 AM
oooo
i'm getting it...thanks jason, serex..that means for a program that add two value it have 2 optional library to running it...wow, different library means different string, right serex... i'm getting it.. thanx for your information i need to learn more about library...where can i get/download library??? is there any???

shmoove
06-14-2004, 08:20 AM
The adding part doesn't need a library. It's the input/output (printing messages to the screen and getting input from the keyboard) parts that need the iostream library (and I think it should be #include <iostream>, not with quotes).

iostream is one of the standard libraries, and it will come with any compiler.

Dev-C++ (http://www.bloodshed.net/devcpp.html) is a good free compiler to get started with...

shmoove

obiwanjabroni
06-15-2004, 07:57 PM
The #include command is including a library of precompiled functions. Functions run tasks. When you use include like "#include<iostream>", it's telling your compiler that the library is inside the default include folder. For instance, iostream and stdio are standard include libraries and are probably located inside the folder of you compiler in another folder called "include". If you include something like "#include "iostream"", you're telling the compiler that iostream is located in the folder of your current project. This is useful for writing your own libraries and separating code so you can manage all of your code better.

Starting with C++, you can use either iostream or stdio, each has a different set of input/output functions. For instance, iostream's main output functions include: cout and cerr, and iostream's main input function is: cin.

stdio was a library that came with C, so it's not the same structure as in C++. stdio uses a simpler notion of functions rather than iostream's use of classes. Hopefully, you'll understand this better as you do more programming. Suffice it to say, stdio is a library not only for input and output from keyboard, but also from files. For keyboard input and output, there are functions like: printf(), cprintf(), sprintf(), scanf().

C++, like any other language, comes with a full set of predefined things that you don't need to include any libraries for. For isntance, C++ comes with predefined operators and a predefined set of keywords For instance, addition. C++ comes with standard operations like:

+ (addition), - (subtraction), * (multiplication), / (division), % (modulus).

More complicated math like square roots or powers must be written as a function. Luckily, most C++ compilers comes with a <math> library that has function for sin, cos, tan, sqrt, and pow.

Also, some keywords in C++, that you've probably noticed since many C++ developing tools change the colors of these words, include:

int, long, double, void, char, using, namespace, extern

If you'd really like to learn C++, I highly recommend buying a book. Sam's "Learn C++ in 24 Hours" is a great book for beginners and as you get more advanced, you can look at www.cplusplus.com and other references you can get from google. If you particularly like game development, www.gamedev.net is a great resource.

Hope that helped.