cout

I have tried to answer this thirty different ways, and I am pretty sure I just don't know exactly what the question is asking me to do..

Two variables , num and cost have been declared and given values : num is an integer and cost is a double . Write a single statement that outputs num and cost to standard output . Print both values (num first, then cost), separated by a space on a single line that is terminated with a newline character . Do not output any thing else.

Can you show us what you have?


Basically what the assignment is saying is:

You have this code:

1
2
int num = 10;           //I have no idea what the real value is..
double cost = 8.99; //I have no idea what the real value is.. 



Now you need to write a single statement. A single statement ends in a semi-colon. ex: int num = 10; is a single statement.


This statement must print both variables ( num and cost in this order ) , separated with spaces and terminated with a newline.

To print you use std::cout separated with << between things to output. So for example if we wanted to print
Hello, World!
it would look like:
std::cout << "Hello, World!";

The format of the output is [num][ ][cost][\n]

So the output will look like:

10 8.99
press any key to continue...
closed account (3hM2Nwbp)
Two variables, num and cost have been declared and given values: num is an integer, and cost is a double.

1
2
3
4
5
int main()
{
  int num = 44;
  double cost = 87.55;
}


Using std::cout, write num, followed by a space, followed by cost, followed by '\n' to the standard output.

1
2
3
4
5
6
7
#include <iostream>
int main()
{
  int x = 97;
  std::cout << "this is how" << "we use std::cout " << x << "\n";
  std::cout << "printed on the next line";
}
this is howwe use std::cout 97
printed on the next line


My keyboard-fu is weak. I concede to ninja giblit
Last edited on
Okay, I got it, thanks.

Apparently it wanted this: std::cout << num << " " << cost << "\n";

What I was doin was the same thing with cout instead of std::cout.

Topic archived. No new replies allowed.