Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么var x显示不正确? #包括// #包括// 使用名称空间std; int main() { 浮点数a,x,y=0;// cout>a;// cout>x;//x cout_C++_Variables_Syntax_Codeblocks - Fatal编程技术网

C++ 为什么var x显示不正确? #包括// #包括// 使用名称空间std; int main() { 浮点数a,x,y=0;// cout>a;// cout>x;//x cout

C++ 为什么var x显示不正确? #包括// #包括// 使用名称空间std; int main() { 浮点数a,x,y=0;// cout>a;// cout>x;//x cout,c++,variables,syntax,codeblocks,C++,Variables,Syntax,Codeblocks,您只是在同一行上打印所有内容,您可以: 在两个第一个结果之后打印它: #include <iostream> // подключаем библиотеку ввода-вывода #include <cmath> // подключаем библиотеку математических функций using namespace std; int main() { float a, x, y = 0; /

您只是在同一行上打印所有内容,您可以:

在两个第一个结果之后打印它:

    #include <iostream> // подключаем библиотеку ввода-вывода
    #include <cmath> // подключаем библиотеку математических функций

    using namespace std;

    int main()
    {
    float a, x, y = 0; // объявление переменных
    cout << "Enter a variable: ";
    cin >> a; // запрос на ввод a
    cout << "Enter x variable: ";
    cin >> x; // запрос на ввод x
    cout << "a = " << a << ", x = " << x; // вывод a и x
    y = (pow(x, 3) + sqrt(1 + pow(x, 3))) / (a + exp(x)); // формула расчета
    cout << y;
    }

Enter a variable: 6
Enter x variable: 7
a = 6, x = 70.327894
或者在另一行上打印
y

Enter a variable: 6
Enter x variable: 7
a = 6, x = 7, y = 0.327894

a=6,x=70.327894

这并不意味着x=70.327894

x为7,结果y为0.327894


您需要小心地打印到终端,使用
您知道
y
的值应该是多少吗?(我的钱在
0.327894
上),所以您的问题是“为什么额外的打印语句会打印额外的内容?”MyBDNILO,我在Python中得到了与你相同的内容,但是在C++中没有。因为你没有在它上面打印一个换行符!<代码> HuffZFrp,谢谢,它工作!
Enter a variable: 6
Enter x variable: 7
a = 6, x = 7, y = 0.327894
cout << "a = " << a << ", x = " << x << "\n"; // returns to another line
y = (pow(x, 3) + sqrt(1 + pow(x, 3))) / (a + exp(x)); // формула расчета
cout << "y = " << y;
Enter a variable: 6
Enter x variable: 7
a = 6, x = 7
y = 0.327894