1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Please help with this program

Discussion in 'C' started by pers, Jul 9, 2012.

  1. pers

    pers New Member

    Jul 9, 2012
    Likes Received:
    Trophy Points:
    Hey everyone, so I've done the most I could do, but I still don't know how to add string, bool, and char into this equation. Could you please help.

    Here are the instructions:
    1. declare a char, an int, 3 float, a double, a string and a bool.
    2. assign values to each of these. This should be done in separate steps from the declaration.
    3. print each variable to the monitor preceeded by a statement saying what you are printing. Example: “here is my char: “ << char;
    4. for each variable, write a statement that will print it’s size to the monitor. The statement should say, “the size of x is: “ followed by variable, followed by an endline.
    5. divide one float by another and put the result in the 3rd float. hint – you can reuse variables if you don’t need their value anymore. Print the result to the screen with a statement like: “x/y = “ x followed by an endline.
    6. perform any other mathematic operations you feel like and print result to screen (but tell me what I’m seeing).

    And here's what I've come up with so far:

    #include <iostream>
    using namespace std;
    int main()


    int i;
    float x, y, z;
    double d;

    i = 15;
    d = 40;
    x = 25;
    y = 125;
    z = y/x;

    cout << "Here's my int: " << 'i' << endl;
    cout << "Here's my first float: " << 'x' << endl;
    cout << "Here's my second float: " << 'y' << endl;
    cout << "Here's my third float: " << 'z' << endl;
    cout << "Here's my double: " << 'd' << endl;
    cout << endl;

    cout << "The size of my int is: " << i << endl;
    cout << "The size of double is: " << d << endl;
    cout << "The size of my first float, x, is: " << x << endl;
    cout << "The size of my second float, y, is: " << y << endl;
    cout << "The size of z, which is y/x, is equal to: " << z << endl;

    return 0;

  2. xpi0t0s

    xpi0t0s Mentor

    Aug 6, 2004
    Likes Received:
    Trophy Points:
    Senior Support Engineer
    >>I still don't know how to add string, bool, and char into this equation

    Why not? You've figured it out for int:
    int i;
    so clearly you know the format is TYPENAME VARIABLENAME SEMICOLON.

    Have a wild guess at how you might declare a string and post the result.

Share This Page