locked
C++ Cout Question....

    Question

  • HI I CAN'T FIGURE THIS OUT. I'M A NEW STUDENT TRYING TO LEARN. PLEASE HELP & EXPLAIN IF POSSIBLE:



     Given an integer variable i and a floating-point variable f, write a statement that writes both of their values to standard output in the following format:

    i=value-of-i f=value-of-f

     Thus, if i's value were 25 and f's value were 12.34, the output would be:

    i=25 f=12.34

     But you don't know what i's value and f's value are. They might be 187 and 24.06. If that's what their values are, the output from your statement should be:

    i=187 f=24.06

     Remember: you are GIVEN i and f-- that means they are already declared and they already have values! Don't change their values by assigning or initializing them! Just print them out the way we have shown above. Just write one statement to produce the output.

     Remember: in your output you must be displaying both the name of the variable (like i) and its value.

    Monday, September 05, 2011 4:00 PM

Answers

  • "It's better to aim high and miss, than to aim low and hit your target"

    Rich, I love it.  What is that a parody or something?  Too many people aiming low, it's security.

     

    as for your question:

    cout << "enter string" << variable; // or any combination there of.

     

    as for initializing variables:

    Always initialize your variables unless you know for a fact that it will be done for you.  Reading data is not too bad, garbage in garbage out.  Writing may have bad results.  Its a good habit to initialize variables, besides some languages (eg. C#) will not let you use the variable till you do.


    David
    Tuesday, September 06, 2011 1:54 AM

All replies

  • Monday, September 05, 2011 4:13 PM
  • Generally speaking, we won't provide direct answers to homework questions. It's part of the learning experience for you to try to figure out the answer on your own. Pierre has kindly shown you a thread that gives some output examples so you can perhaps try to adapt it to your homework assignment. Also note that your introductory C++ textbook (assuming you have one) will have a section dedicated input/output.
    Monday, September 05, 2011 4:19 PM
  • I have read the forums and still have trouble with this question. I don't want direct answers but an explanation on what to do. Any help would be appreciated.
    It's better to aim high and miss than to aim low and hit your target.
    Monday, September 05, 2011 5:35 PM
  • Monday, September 05, 2011 10:26 PM
  • OT

    It's better to aim high and miss than to aim low and hit your target.

    I don't think so. Why is it better?
    Tuesday, September 06, 2011 1:10 AM
  • "It's better to aim high and miss, than to aim low and hit your target"

    Rich, I love it.  What is that a parody or something?  Too many people aiming low, it's security.

     

    as for your question:

    cout << "enter string" << variable; // or any combination there of.

     

    as for initializing variables:

    Always initialize your variables unless you know for a fact that it will be done for you.  Reading data is not too bad, garbage in garbage out.  Writing may have bad results.  Its a good habit to initialize variables, besides some languages (eg. C#) will not let you use the variable till you do.


    David
    Tuesday, September 06, 2011 1:54 AM