c++ - 我正在使用命令提示符在 C++ 中做一个非常简单的应用程序

标签 c++

我做的是加法、乘法、减法和除法。我正在通过我的命令提示符运行它,但我不知道如何制作它,所以每次计算之间都有一个空格。或者即使我可以把它们放在不同的线路上。但只要一个空间就可以了。

#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/

相关文章:

c++ - 安置问题 - 新!

c++ - i + 1 < vec.size() 和 i < vec.size() - 1 之间的区别

c++ - 不兼容的类声明 c++

c++ - 是否可以混淆 RTTI 数据?

c++ - 简单程序引用错误

c++ - 计算不同数字数量的省时方法

c++ - 几个数的最大值

c++ - 在类中创建线程并在类 C++ 中使用它

C++ 获取进程所有者/当前用户 token

c++ - 当多个高优先级线程在多个内核上运行时,Linux 内核无响应