我做的是加法、乘法、减法和除法。我正在通过我的命令提示符运行它,但我不知道如何制作它,所以每次计算之间都有一个空格。或者即使我可以把它们放在不同的线路上。但只要一个空间就可以了。
#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
}
最佳答案
将其放在每行之间或行尾或正在打印的字符串中。
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
}
关于c++ - 我正在使用命令提示符在 C++ 中做一个非常简单的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8810819/