Simple calculator using command line with C++

后端 未结 5 441
遇见更好的自我
遇见更好的自我 2021-01-26 10:57

I\'m writing a project that we do simple calculator from command line. The users input in this format programname firstNumber operator secondNumber. Here what I

5条回答
  •  再見小時候
    2021-01-26 11:56

    In the lines

    double firstNumber = atoi(argv[1]);
    

    and

    double secondNumber = atoi(argv[3]);
    

    atoi converts the parameter into an int (hence truncating after the decimal point). You need to convert it into a double. You should instead use std::atof, or, if using C++11, may also use std::stod(argv[1]);.

提交回复
热议问题