Hell_Demon (10-08-2009),zeco (10-08-2009)
Hallopeople. :O
I'm new to C, and C++. Reading a pretty old book as well, written...no idea when. Anyways, the book is by Sam A. Abolorous. It's called 'Learn C In Three Days'. Possible, not possible, I don't know considering I wanna take my time with programming and not burn through it. Rushing it, learning it, then when you try to apply it to something else, your like what? No, I wanna learn it properly so I can apply it wherever needed.
Anyways, back to the question. o_o So the book has a code...and it gives an example of declaring variables. I tried inputting that code, TRIED modifying it and still no luck. I get errors. I'll post the code I tried. Keep in mind I used MICROSOFT VISUAL C++.
The code from the book.
Thanks to whoever helps me out. ^_^Code:*****#include <stdafx.h> #include <stdio.h> main() { //Declarations. int a; float b; //Assignment. a=1024; b=512; //Display output. printf("%d\n",a); printf("%f\n",b); }
EDIT: I dunno how to use the code thingy...so I apologize about that. ._.
EDIT: Thanks Zeco for teaching me how to put the code.
ALRIGHT, whee. I used DevC++, and it worked. I somewhat changed the script so it pauses for a while. Thanks Why06 for the tip. FINAL:
Code:#include <stdio.h> #include <conio.h> int main() { //Declarations. int a; float b; //Assignment. a=1024; b=512; //Display output. printf("%d\n",a); printf("%f\n",b); getch(); }
Hell_Demon (10-08-2009),zeco (10-08-2009)
Don't really see anything wrong with that :/, except maybe putting int, infront of Main. Never really tried to see if the compiler assumes a void in that situation.
By the way, congratulations on being the most respectably new person to come to this site in Days, maybe weeks =)
And to use the code box thingy, put your code between a (code) and a (/code), except replace the regular brackets with square brackets [ ] [/ ]
Code looks well enough to me. Too lazy to compile it.
Before your main function some compilers require you put. int or void
example: void main()
also you might want to get into the habbit of putting decimals in float variables.
example: like 5.0 etc
those would probably make my compiler take it. visual studio 2008
Same i just recently started to learn c++ so i can't help u but it looks like they already have.
[IMG]https://i644.photobucke*****m/albums/uu165/geebes888/V1.png[/IMG]
-Advertisements(Permanent ban)
-Flaming(1+ day ban)
-Nazi or Racist content/comments ( 5+ day ban)
-Bumping old threads 1 week or older( 3 day ban)
-Using outside download sources "Links"( 3+ day ban)
-Spamming( 1+ day ban) -Begging for hacks ( 1 day ban)-
No virus scan( 1 day ban) -Fake VirusScan ( 7+ day ban) -Posting Viruses,keyloggers (permanent ban) -
Disrespect of Staff members (5+ day ban)
OMfG i hate hate noobs that ask for hacks they shuld just go in a hole and die
Thank me if i helped, or just thank me anyway
[Respect list]
Toymaker- for his crack hacking team.
[MPGH]-XpliCitt-
[MPGH]User1
[MPGH]Liz
[MPGH]Whitten
It helps if you post the errors because those help immensely =)
Hmmm.... well I just compiled it as a C file in my Dev-C++ compiler and it seems to have worked. All I had to do was comment out the first #include statement. Weird. I didn't know the compiler would default like that in the case of main().
Another problem is that it flashes up on the screen really fast so you can't see it. So I would include this system("pause"); on the last line so you can see what you wrote.
using namespace std; ? Don't know if it's needed with a printf statement
Whee, thanks to everyone that replied!
I'll try the script now with some modfications listed above in Dev C++ now. I was using MS Visual C++ earlier.
EDIT: My very first own attempt at coding an assignment from the book. Kinda happy considering I didn't have to use the book for it.
Code:#include <stdio.h> #include <conio.h> int main() { //Delcarations. double number; //Assignments number=3.45678; //Output printf("%.0f\n", number); printf("%.2f\n", number); getch(); }
Congratulations
Adding you to my respected list
Ah we-a blaze the fyah, make it bun dem!
Thank you very much! And I'm honored to be on your respect list.
I'm glad, considering even though I'm new, people are friendly and really helpful. :3
Oh, and just posting how far I am along now. I've just finished learning Pointers.
Code:#include <stdio.h> #include <conio.h> int main() { //Declarations. char *a, *b; //Assignment. a="Hello Again, I'm being pointed to the character a!"; b="Hello Again, I'm the pointer for the character b!"; printf("%s\n%s\n",a,b);// NTS: For every character(a,b), add a string spec. getch(); }
That's true. LOL, It just makes everything alot easier. After I'm done memory locations, I'm gonna try to code something that I've learnt from Chapter 1 overall. Just as a review, look at my notes to see what I've learnt and yee.
EDIT:
Uh. o_o Question for anyone that's reading this atm!
So I'm doing examining Memory Locations atm, and the book I'm reading gives that code as an example to do. I wrote it word for word, exactly how it should be and yet I get a different answer.Code:#include <stdio.h> #include <conio.h> int main() { char *a; a="Hello again "; printf("%s\n" ,a); printf("%c\n" ,*a); printf("%d\n" ,a); printf("%p\n" ,a); printf("%d\n", *a); getch(); }
The output is supposed to be,
Yet I'm getting...Code:Hello again H 168 00A8 72
Does anyone know what I did wrong? Or can anyone explain what I'm doing wrong?Code:Hello again H 4206592 <-----=Incorrect 00403000 <----- =Incorrect 72
Much appreciated, thanks!.