hello. basic questions

This is a discussion on hello. basic questions within the C++ Programming forums, part of the General Programming Boards category; hey guys and girls.... if any. i have some basic questions ....... study guide our teacher gave us. 1. in ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    6

    hello. basic questions

    hey guys and girls.... if any.

    i have some basic questions ....... study guide our teacher gave us.

    1. in this line what part is directly related to declaring the variable....
    and also what part is related directly to initializing the variable.....

    double age = 0;

    2. i have to declare and initialize a variable to suit this data. ill show you what i put...
    correct me if you know better

    shoe size ------------------- int size = 0;
    price airline ticket ----------- double price_ticket = 0;
    grade on a homework ------------------ char = ' ' = A is best, B is good , C is average
    number of letters in a word ------------------ dont know
    a letter of the alphabet -------------------- dont know

    3. i have to give preprocessor directives that show

    - PI - #include ---------------------------------------<math.h> --- i know that one
    -avogadros number --------------------------------- havent learned
    - number minutes in an hour ------------------------- dont know

    4. what are the advantages to using a constant as opposed to a variables in a code

    5. what are the results of these when done in c

    456.5/59 =
    25/45 =
    (double)65/59
    62/45.6
    (int)((int)10.4/(double)4)
    Last edited by johnnyboy; 01-31-2008 at 05:09 PM.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,535
    So tell us what you know first. We can't solve your homework for you.
    I'll tell you something, however. There are 3 basic groups of variables available. They are:

    Integer - numbers. For example, 10.
    Char - characters or strings. Used to hold letters like 'a' or "hello world".
    Floating point - numbers with decimals, like 10.50.

    Knowing these types should make you able to answer the question 2 questions.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    6
    hahahahaa its not homework.

    i did what i could, the rest is like wierd to me.

    i know theres three types of variables.... did i do the first three right?? for question two...

    for the last section i dont know if shes looking for the answer as int or double form

    or if she just wants us to put int, double, whatever...

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,535
    You said it yourself:
    study guide our teacher gave us.
    The first three of q2 are fine.
    As for the last, these numbers will give an answer in either double or int depending on what type of numbers are used to divide with each other.
    If you divide a double with int, the answer is double, for example.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    6
    its a study guide... meaning if we want to learn more, practice with this worksheet.

    we dont turn it in an dits not homework. i just need the extra practice.

    with that in mind, please helppppp

    for part 2 what are the last ones

    for part three what are the last 2 ?

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    10
    I won't give direct answers but here are some pointers:

    1. in this line what part is directly related to declaring the variable....
    and also what part is related directly to initializing the variable.....
    double age = 0;

    As you can see here, two things are happening. The variable age is being created as a double, and secondly, 0 is being assigned to it. Once part of this is the declaration, the second is the initialization.

    2. i have to declare and initialize a variable to suit this data. ill show you what i put...
    correct me if you know better


    shoe size ------------------- int size = 0; // I dont know if a shoe size of 0 exists, also there may be half sizes.
    price airline ticket ----------- double price_ticket = 0; // I agree
    grade on a homework ------------------ char = ' ' = A is best, B is good , C is average // I agree
    number of letters in a word ------------------ dont know // *Number* of letters...
    a letter of the alphabet -------------------- dont know // *A letter* of the alphabet

    3. i have to give preprocessor directives that show

    - PI - #include ---------------------------------------<math.h> --- i know that one // Correct in a way, however not what the teacher is looking for. I believe she wants #define (Note that #define is not complete by itself).
    -avogadros number --------------------------------- havent learned
    - number minutes in an hour ------------------------- dont know

    4. what are the advantages to using a constant as opposed to a variables in a code
    Google it or check the tutorials on this site.

    5. what are the results of these when done in c
    456.5/59 =
    25/45 =
    (double)65/59
    62/45.6
    (int)((int)10.4/(double)4)


    Why not try them?

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,535
    Alright, some pointers...

    Quote Originally Posted by johnnyboy View Post
    1. in this line what part is directly related to declaring the variable....
    and also what part is related directly to initializing the variable.....

    double age = 0;
    You should know how to define a variable right? That means it's a variable definition plus some extra. It should be a cinch.

    number of letters in a word ------------------ dont know
    a letter of the alphabet -------------------- dont know
    As you were already given a hint. The first one is a count. And what do you use for count? Integers, floating or characters?

    3. i have to give preprocessor directives that show

    - PI - #include ---------------------------------------<math.h> --- i know that one
    -avogadros number --------------------------------- havent learned
    - number minutes in an hour ------------------------- dont know
    I'm not sure what it's after.

    4. what are the advantages to using a constant as opposed to a variables in a code
    I'll help you a little.
    A constant is a variable whose value cannot change. IF you try to change it, you get a compile error. So what are they good for?

    5. what are the results of these when done in c

    456.5/59 =
    25/45 =
    (double)65/59
    62/45.6
    (int)((int)10.4/(double)4
    456.5 = double
    25 = int
    When dividing with a floating point, the result is always floating point (you should include the decimals).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    6
    so is "double age" - declaring

    = 0; = initalizing

    ------------- or is it something simple like double = declaring , 0; = initlaizing


    i still dont know the last 2 for part 2....... it ........es me off hahaha


    ............... as far as part three..... preprocessor directives

    im pretty sure number one is #include <math.h>

    the second two i dont know.... i dont think shes looking for #define PI 3.14159


    but you may know better

    Ill look up number 4

    part 5......

    tell me if these look right

    1 ---- 7.74 or double
    2 ------ 0 or int
    3------- 1.10 or double
    4 -------- 1.36 or double
    5------- 2.5 or double

    ok as far as that goes, should i add the default six characters at the end...

    and...... is it int/double = int
    or double/int = int

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,535
    Quote Originally Posted by johnnyboy View Post
    so is "double age" - declaring
    Yes!
    double age
    is defining the variable and
    = 0;
    is initializing it.

    i still dont know the last 2 for part 2....... it ........es me off hahaha
    Then you'll have to think. The answer is right before your nose.
    How would you could the number of numbers in the alphabet, for example?

    but you may know better
    I don't know what it means.

    5------- 2.5 or double
    This is not right.
    The answer would typically be a double because one of the numbers is a double.
    HOWEVER, the (int) at the beginning also tells the compiler to cast the result to an int. So no decimals.

    ok as far as that goes, should i add the default six characters at the end...
    Don't know what you mean?

    and...... is it int/double = int
    or double/int = int
    double/int = double
    int/double = double
    int/int = int
    double/double = double
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Jan 2008
    Posts
    6
    hey thanks i guess. still not understanding it all....

    its not homework, i just want to know.... pleaseeeeee. im not asking you to code me a program or anything! haha

    so for part 5 it would be just 2, not 2.5

    oh and.... the default chracters meaning like if i put %.2lf , any given number would be like 50.56, as opposed to default six places after decimal like

    50.564323

    so what im saying is should i add the rest of the decimals on the end.....

    for part three, i need those preprocessor directives for the last two out of the three. i dont know them ... is avogadros in the math library....
    i have no clue about the third one

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,535
    Quote Originally Posted by johnnyboy View Post
    hey thanks i guess. still not understanding it all....

    its not homework, i just want to know.... pleaseeeeee. im not asking you to code me a program or anything! haha
    Come on! Use your head!
    I'm sure you have one!

    This word:
    "Word"
    How many characters or letters are in there?

    And

    This:
    a
    Is a letter, right? So what format would you use to represent it inside a program?

    so for part 5 it would be just 2, not 2.5
    That's right.

    oh and.... the default chracters meaning like if i put %.2lf , any given number would be like 50.56, as opposed to default six places after decimal like

    50.564323

    so what im saying is should i add the rest of the decimals on the end.....
    Since there's no information saying how many decimals you should keep... well, you could run them inside a program to test and save the result. Be sure to tell what type of number the answer is too.

    for part three, i need those preprocessor directives for the last two out of the three. i dont know them ... is avogadros in the math library....
    i have no clue about the third one
    I don't know what the original question meant.
    Never heard of avogadros number either.
    And what does "number minutes in an hour" have to do with preprocessor?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by johnnyboy
    3. i have to give preprocessor directives that show

    - PI - #include ---------------------------------------<math.h> --- i know that one
    -avogadros number --------------------------------- havent learned
    - number minutes in an hour ------------------------- dont know
    take these
    Code:
    #define PI 3.1415926535897
    #define AVOGADROS_NUMBER 6.022e23
    #define MINUTES_IN_HOUR 60
    Quote Originally Posted by johnnyboy
    hey guys and girls.... if any.
    are there any girls
    Last edited by manav; 02-01-2008 at 03:51 AM.

  13. #13
    Registered User
    Join Date
    Jan 2008
    Posts
    6
    Yea i got everything now minus declaring initializing a variable for

    number of letters in a word -------------- int letters_word = 0;

    a letter of the alphabet --------------- char = ' '; any letter


    Tell me if I did those right......

    And whoever was right about the prep dir. for defining those variables was right, I found out..... Sorry

  14. #14
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,535
    Yes, that's right. An integer is used for counting and a char is used for storing a character.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic Questions
    By Panda_ in forum C Programming
    Replies: 15
    Last Post: 09-23-2009, 04:24 PM
  2. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  3. Some Basic questions
    By BlaX in forum C Programming
    Replies: 7
    Last Post: 06-30-2009, 09:51 AM
  4. Please help, basic unsigned conversion questions
    By ninjacookies in forum C Programming
    Replies: 3
    Last Post: 04-20-2005, 10:50 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21