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?
3 Antworten
+ 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;
}
+ 1
Should it always print '^' in between the 2 input numbers?
+ 1
Yes.