0

How to put input and output in same line.

Cin and cout in same line, like input(2) output(^) input(3) output(=), So that it looks like 2^3= Instead of 2 ^ 3 = Plz help, and is it necessary to put input output in same line while developing app?

17th Feb 2021, 12:50 PM
ACE
ACE - avatar
3 odpowiedzi
+ 2
About "necessity" of printing input & output in the same line; it depends on how the coder sees it. For example, when an input was expected to be long enough that it can't fit in the remaining space (after the input prompt) without splitting the input in to multiple lines (e.g. a long string), then it might be a good idea to read the input in its own line. In this case, you're taking 2 int numbers (max 11 characters each), so it's fine to print them in the same line. #include <iostream> #include <cmath> // pow int main() { using std::cin, std::cout; int num1 {0}, num2 {0}; cin >> num1; cout << num1; // only needed in Code Playground cout << " ^ "; cin >> num2; cout << num2; // only needed in Code Playground cout << " = "; cout << pow( num1, num2 ); return 0; }
18th Feb 2021, 5:35 AM
Ipang
+ 1
Should it always print '^' in between the 2 input numbers?
17th Feb 2021, 1:08 PM
Ipang
+ 1
Yes.
18th Feb 2021, 3:50 AM
ACE
ACE - avatar