154k views
1 vote
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.

1 Answer

6 votes

// Writing a C++ Program for the given senario

#include<iostream> // Using input and output stream

using namespace std; // Using standard namespace

// Main function

int main(){

int num = 10; // int num initialized with 10

double cost =1000; // double cost initialized with 1000

/*

Cout is stream in C++ that uses << symbol to output anything on the screen and as the problem says we need to output both numbers on a line, i have used multiple << because on cout streams you are allowed to send one element at a time.

Also, endl is a keyword in C++ that ends the line after output for the cout stream is finished.

*/

cout<< num << " " << cost <<endl;

// Return 0 means telling the compiler to terminate the //program

return 0;

}

User Help
by
5.7k points