Page 1 of 3 123 LastLast
Results 1 to 15 of 36
  1. #1
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky

    Declaring variables. I r newb.

    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.

    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);
    }
    Thanks to whoever helps me out. ^_^

    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();
    }
    Last edited by crushed; 10-08-2009 at 05:53 PM.

  2. The Following 2 Users Say Thank You to crushed For This Useful Post:

    Hell_Demon (10-08-2009),zeco (10-08-2009)

  3. #2
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    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 [ ] [/ ]

  4. #3
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    Quote Originally Posted by zeco View Post
    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 [ ] [/ ]
    Ah, so I see. The code isn't the fault. I've downloaded DevC++, so I'll try inputting it in that tommorrow. It's time for me to sleep. Almost 2 AM! XD

    Thank you for letting me know how to use the code, I'll try it. And thanks for the welcoming gesture as well.

  5. #4
    howl2000's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    USA
    Posts
    99
    Reputation
    10
    Thanks
    3,130
    My Mood
    Busy
    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

  6. #5
    geebes888's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    144
    Reputation
    10
    Thanks
    17
    My Mood
    Sneaky
    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

  7. #6
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    It helps if you post the errors because those help immensely =)

  8. #7
    why06jz's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Posts
    295
    Reputation
    14
    Thanks
    54
    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.

  9. #8
    BooYa's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Location
    hre
    Posts
    111
    Reputation
    10
    Thanks
    19
    using namespace std; ? Don't know if it's needed with a printf statement

  10. #9
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Quote Originally Posted by BooYa View Post
    using namespace std; ? Don't know if it's needed with a printf statement
    It isn't. =)

  11. #10
    Pixipixel_'s Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    VCExpress.exe || France :D
    Posts
    2,087
    Reputation
    27
    Thanks
    742
    My Mood
    Cool
    Quote Originally Posted by BooYa View Post
    using namespace std; ? Don't know if it's needed with a printf statement

    Nah it's useless. If you use cout << "blabla"; (C++) use using namespace std;
    printf is in C, not in C++ wich use cout.

  12. #11
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    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();
    }
    Last edited by crushed; 10-09-2009 at 01:38 AM.

  13. #12
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Congratulations
    Adding you to my respected list
    Ah we-a blaze the fyah, make it bun dem!

  14. #13
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    Quote Originally Posted by Hell_Demon View Post
    Congratulations
    Adding you to my respected list
    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();
    }

  15. #14
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Quote Originally Posted by crushed View Post
    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();
    }
    Pointers are quite fun =). Just be careful with them. Pointers are really cool, but if you aren't careful stuff could blow up ^^

  16. #15
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    Quote Originally Posted by zeco View Post
    Pointers are quite fun =). Just be careful with them. Pointers are really cool, but if you aren't careful stuff could blow up ^^
    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!
    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();
    }
    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.
    The output is supposed to be,
    Code:
    Hello again
    H
    168
    00A8
    72
    Yet I'm getting...
    Code:
    Hello again
    H
    4206592   <-----=Incorrect
    00403000  <----- =Incorrect
    72
    Does anyone know what I did wrong? Or can anyone explain what I'm doing wrong?
    Much appreciated, thanks!.
    Last edited by crushed; 10-09-2009 at 07:40 PM. Reason: Question.

Page 1 of 3 123 LastLast

Similar Threads

  1. i no y k2 r newbs =)
    By jkmacnak in forum WarRock - International Hacks
    Replies: 2
    Last Post: 05-26-2007, 09:15 PM
  2. newb question =(
    By fable741 in forum WarRock - International Hacks
    Replies: 3
    Last Post: 05-09-2007, 08:21 AM
  3. NEWBS SIG PLS :d
    By SATANICAT in forum Help & Requests
    Replies: 3
    Last Post: 01-04-2007, 06:09 AM
  4. LOL @ Amazon those newbs
    By SATANICAT in forum General
    Replies: 16
    Last Post: 09-02-2006, 04:47 PM
  5. Notice: To spamming newbs.
    By Dave84311 in forum General
    Replies: 0
    Last Post: 12-26-2005, 10:56 PM

Tags for this Thread