CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012
    Posts
    4

    Really need help with this program

    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. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,613

    Re: Really need help with this program

    You'd declare a string, a bool and a char the same way you'd declare an int or a double.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



HTML5 Development Center

Click Here to Expand Forum to Full Width