Jump to content
Eternal Lands Official Forums
Sign in to follow this  
Wolf_Lord

First C++ Program :<)

Recommended Posts

The File was

 

//

//  Program to convert temperature from Celsius degree

//  units into Fahrenheit degree units:

//  Fahrenheit = Celsius  * (212 - 32)/100 + 32

//

#include <cstdio>

#include <cstdlib>

#include <iostream>

using namespace std;

 

int main(int nNumberofArgs, char* pszArgs[])

{

  // enter the temperature in Celsius

  int celsius;

  cout << "Enter the temperature in Celsius:";

  cin >> celsius;

 

  // calculate conversion factor for Celsius

  // to Fahrenheit

  int factor;

  factor = 212 - 32;

 

  // use conversion factor to convert Celsius

  // into Fahrenheit values

  int fahrenheit;

  fahrenheit = factor * celsius/100 + 32;

 

  // output the results (followed by a NewLine)

  cout << "Fahrenheit value is:";

  cout << fahrenheit << endl;

 

  // wait until user is ready before terminating program

  // to allow the user to see the program results

  system("PAUSE");

  return 0;

}

 

I got it out of the C++ for Dummies book, I'm also using this website http://www.cprogramming.com/tutorial.html to compliment the C++ for dummies book :D

 

LOL Hammen

C++ is great isn't it?
I don't know, I'm just getting started :D But your right it's most likely simply a C program... but what do I know.

 

Chatterbug Nope sorry,

 

#include <iostream.h>

int main()

{

cout << "Hello World ^^";

}

 

Was my second program ;), I'm doing it all back aswards it would seem, I started with the hard stuff :lol: ;) :lol:

 

 

Good luck thou

 

Thank you very much :D

 

NeoSeS

Share this post


Link to post
Share on other sites

For the fahrenheit program: What the **** is cstdio used for? It's included but I don't see it used anywhere.

 

For the hello-world program: It's #include <iostream>, not #include <iostream.h>. iostream.h is usually a special backwards-compatible library meant for programs written before the C++ standard was finalized (i.e. old crap), and lacks important things like namespaces, where as iostream (without .h) is the one you should be using when writing a program.

Share this post


Link to post
Share on other sites
For the fahrenheit program: What the **** is cstdio used for?

 

Darned if I know Leeloo, I just wrote the program the way it was in the book, I don't even know what cstdio or iostream or any of these includes are yet. Give me time, I'm sure I'll figure it out eventualy...

 

 

not #include <iostream.h>.

 

You'll have to ask chatterbug, that was their program line not mine, I just copied and pasted it, I think when I wrote a similar program it was just the "#include iostream" line, I don't know what the "iostream.h" is at all.

 

 

Nice work neoses. You'll be coding server-side EL before we know it

 

LOL thank you Placid, we'll see what happens :rolleyes:, right now I'm still looking into Boolean Algebra and studying variables more closely.

 

Catch you all later,

NeoSeS

Share this post


Link to post
Share on other sites
For the hello-world program: It's #include <iostream>, not #include <iostream.h>. iostream.h is usually a special backwards-compatible library meant for programs written before the C++ standard was finalized (i.e. old crap), and lacks important things like namespaces, where as iostream (without .h) is the one you should be using when writing a program.

 

Yeah, I know...I started originaly reading out of some older book and got in the habbit of it. I'll be reading out of new sources now so i'll break my habbit.

Share this post


Link to post
Share on other sites
Coding EL in C++?

 

Even if EL is not coded in C++, C++ is a steping stone to learning other languages isn't it? Once I learn and am fluent in C++ then I can move on to other projects and languages :rolleyes: I don't know what I'm going to do with my newly aquired knowledge, but it's fun just to learn new things so, we'll just see what teh future holds.

 

NeoSeS

Share this post


Link to post
Share on other sites

Yes, it's always easier to learn the second language, at least as long as it's the same genre (i.e. don't expect C++ knowledge to be useful if you go for Prolog or Lisp :D), and for C, it does have a lot in common with C++, possibly even too much. At least get good with C++ first, so you don't start mixing the two.

 

Some people will tell you to learn C first, but I think learning C++ before C is actually better, because a C compiler will tell you if you by mistake wrote some C++ code, where as writing C code in a C++ compiler gives no complaints (usually), so someone who learnt C first will never learn to write C++ unless he puts a big effort into not writing C. Otherwise he will just continue writing C code.

Share this post


Link to post
Share on other sites
(i.e. don't expect C++ knowledge to be useful if you go for Prolog or Lisp :P)

Helps a bit ... Even though all I know are a bunch of curly-brace languages and BASIC, LISP still seemed a lot easier than learning a first langauge.

Share this post


Link to post
Share on other sites
(i.e. don't expect C++ knowledge to be useful if you go for Prolog or Lisp :huh:)

Helps a bit ... Even though all I know are a bunch of curly-brace languages and BASIC, LISP still seemed a lot easier than learning a first langauge.

Someone who learned LISP as the first language might suggest that this is because LISP is much easier to learn in general :D

 

OTOH, I tried to learn Scheme (a lot like LISP, if I'm not mistaken) for making Gimp scripts, but gave up - that language is just too different. And I already knew Basic, C, C++, Prolog, Miranda, a bit Postscript and 6502 (6510) and x86 assembly.

Share this post


Link to post
Share on other sites
who want to see code to make a program to format the hard drive  ?

 

if you do  pm me .

??

 

Here, I'll give a program out for free:

#!/bin/sh

partition = $1

mke2fs -j -T news $partition

 

I'm sure Leeloo has something to comment on this program, but nvm that. It should work.

 

EDIT: Oh, btw, congratulations neoses, gj :)

Edited by Grum

Share this post


Link to post
Share on other sites
#!/bin/sh

partition = $1

mke2fs -j -T news $partition

 

I'm sure Leeloo has something to comment on this program, but nvm that. It should work.

You mean, like why $partition, just use $1 and make it a one-liner? :blink:

Share this post


Link to post
Share on other sites
#!/bin/sh

partition = $1

mke2fs -j -T news $partition

 

I'm sure Leeloo has something to comment on this program, but nvm that. It should work.

You mean, like why $partition, just use $1 and make it a one-liner? :P

lol, I was thinking that. What IS the point of assigning the first param to the partition var Grummy? :)

Share this post


Link to post
Share on other sites
#!/bin/sh

partition = $1

mke2fs -j -T news $partition

 

I'm sure Leeloo has something to comment on this program, but nvm that. It should work.

You mean, like why $partition, just use $1 and make it a one-liner? :P

lol, I was thinking that. What IS the point of assigning the first param to the partition var Grummy? :)

The point is, that I always forget what the parameters in a shell script are, so I've made it a habit to assign more or less meanigful names to them in the beginning of the script. I agree that probably in this case it was overkill, but in general I've found it very useful.

Share this post


Link to post
Share on other sites
The point is, that I always forget what the parameters in a shell script are, so I've made it a habit to assign more or less meanigful names to them in the beginning of the script. I agree that probably in this case it was overkill, but in general I've found it very useful.

Ahh dont get me wrong, I see why you did it, just didnt think it was necessary. :D

Share this post


Link to post
Share on other sites

hmmz... i tried programming C++, found it pretty boring, cause i couldn't do anything with it yet and besides that i heart is with programming websites in html php and javascript but neo congratz with your first prog and good luck with further programming :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×