我正在制作它所以它添加,倍数,减法和除法。我通过我的命令提示符运行它,我不知道如何使它,所以每个计算之间有一个空格。或者即使我可以将它们分开来。但只是一个空间就可以了。
#include <iostream> //io from console
int main() //app entry point
{
int num1; //first variabe
int num2; //second variable
int sum; //sum of 2 variabes
int product; //product of 2 variabes
int difference; //differencr of 2 variabes
int quotient; //quotient of 2 variabe
std::cout << "Enter first number: "; //prompt user for input
std::cin >> num1; //assigns input to num1
std::cout << "Enter second number "; //prompt user for input
std::cin >> num2; //assigns inout to num2
sum = num1 + num2; //calcs the sum
std::cout << "The sum is " << sum; //displays the sum
product = num1 * num2; //calcs the product
std::cout << " The product is " << product; //displays the product
difference = num1 - num2; //calcs the product
std::cout << " The difference is " << difference; //displays the difference
quotient = num1 / num2; //calcs the quotient
std::cout << " The quotient is " << quotient; //displays the quotient
}
答案 0 :(得分:4)
将它放在每一行之间或行尾或您正在打印的字符串中。
std::cout << "\n";
或在每个输出行的末尾添加<< endl;
。
使用\n
为您添加了以下示例。
#include <iostream> //io from console
int main() //app entry point
{
int num1; //first variabe
int num2; //second variable
int sum; //sum of 2 variabes
int product; //product of 2 variabes
int difference; //differencr of 2 variabes
int quotient; //quotient of 2 variabe
std::cout << "\nEnter first number: "; //prompt user for input
std::cin >> num1; //assigns input to num1
std::cout << "\nEnter second number "; //prompt user for input
std::cin >> num2; //assigns inout to num2
sum = num1 + num2; //calcs the sum
std::cout << "\nThe sum is " << sum; //displays the sum
product = num1 * num2; //calcs the product
std::cout << "\n The product is " << product; //displays the product
difference = num1 - num2; //calcs the product
std::cout << "\n The difference is " << difference; //displays the difference
quotient = num1 / num2; //calcs the quotient
std::cout << "\n The quotient is " << quotient; //displays the quotient
}
答案 1 :(得分:2)
您可以将光标移动到以下行,如下所示:
std::cout << "\n";
std::cout << std::endl;
endl
选项也会强制流进行刷新。
您的代码可能如下所示:
product = num1 * num2;
difference = num1 - num2;
std::cout << " The product is: " << product << "\n";
std::cout << " The difference is " << difference << std::endl;
答案 2 :(得分:1)
您可以使用:
std::cout << std::endl;
添加新行
答案 3 :(得分:0)
每次添加<< std::endl
以输出换行符号。