C++ Cin似乎在此循环中失败。谁能解释一下我是什么';我做错了?

C++ Cin似乎在此循环中失败。谁能解释一下我是什么';我做错了?,c++,C++,我在尝试构建下面的代码时遇到了一个编译器错误,我不太理解失败的原因和原因 它指向第45行(cin>>x[ctr]),并在“struct std::enable_if'”消息中显示“没有名为“type”的类型” 我几天前才开始编写代码,英语不是我的母语。如果此问题低于社区的薪资等级,则表示歉意。希望你能给我指出正确的方向 cpp.sh/34sm3 #include <cstdio> #include <cstdlib> #include <iostream> #

我在尝试构建下面的代码时遇到了一个编译器错误,我不太理解失败的原因和原因

它指向第45行(cin>>x[ctr]),并在“struct std::enable_if'”消息中显示“没有名为“type”的类型”

我几天前才开始编写代码,英语不是我的母语。如果此问题低于社区的薪资等级,则表示歉意。希望你能给我指出正确的方向

cpp.sh/34sm3

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
//#include "_pause.h"


using namespace std;


//////////////////////////////////////////////////////////////////
//                               NOTE
// This is your program entry point. Your main logic is placed
// inside this function. You may add your functions before this
// "main()", or after this "main()" provided you added reference
// before this "main()" function.
//////////////////////////////////////////////////////////////////


//Write a program that can divide six non-zero integers (two integers per division) from the user and display the result to the user. 
//Create a function that will perform the division operation. Display only the non-decimal part of the quotient.




float quot (int num1, int num2)
{
    return num1/num2;
}


int main() 
{
    // ************************** TO DO **************************
    // Place your code logic after this comment line
    // ***********************************************************
    int x[6];
    cout<<"Enter 6 integers to divide: ";
    for(int ctr=0; ctr<6; ctr++)
    {
        cin>>[ctr];
        if(x[ctr]==0)
        {
            cout<<"Invalid number! Please enter a non-zero value: ";
            cin>>x[ctr];
        }
    }


    cout<<"The quotient of the first pair is: " << quot(x[0],x[1]) <<endl;
    cout<<"The quotient of the second pair is: " << quot(x[2],x[3]) <<endl;
    cout<<"The quotient of the third pair is: " << quot(x[4],x[5]) <<endl;


    system ("pause");
    return EXIT_SUCCESS;
}
#包括
#包括
#包括
#包括
//#包括“\u pause.h”
使用名称空间std;
//////////////////////////////////////////////////////////////////
//注
//这是您的程序入口点。你的主要逻辑是
//在这个函数里面。您可以在此之前添加函数
//“main()”,或在此“main()”之后添加引用
//在此“main()”函数之前。
//////////////////////////////////////////////////////////////////
//编写一个程序,可以从用户处除掉六个非零整数(每个除法两个整数),并将结果显示给用户。
//创建将执行除法运算的函数。仅显示商的非小数部分。
浮点数(整数m1,整数m2)
{
返回num1/num2;
}
int main()
{
//要做的事**************************
//将代码逻辑放在此注释行之后
// ***********************************************************
int x[6];

我想你需要用
cin>>x[ctr]
替换
cin>>[ctr]
…这可能会修复你的错误。

我想你需要用
cin>[ctr]
替换
x[ctr]
…这可能会修复你的错误。

这就是你所要做的一切。 只需将
cin>>[ctr]
更改为
cin>>x[ctr]

它位于第41行。您需要在索引
[ctr]
之前指定数组名
x
这是你的密码

我建议您使用调试器自己找出这些人为的小错误。 此外,在寻求解决方案之前,请阅读您的代码并尝试将其流程可视化

int main() 
{
    // ************************** TO DO **************************
    // Place your code logic after this comment line
    // ***********************************************************
    int x[6];
    cout<<"Enter 6 integers to divide: ";
    for(int ctr=0; ctr<6; ctr++)
    {
        cin>>x[ctr];
        if(x[ctr]==0)
        {
            cout<<"Invalid number! Please enter a non-zero value: ";
            cin>>x[ctr];
        }
    }


    cout<<"The quotient of the first pair is: " << quot(x[0],x[1]) <<endl;
    cout<<"The quotient of the second pair is: " << quot(x[2],x[3]) <<endl;
    cout<<"The quotient of the third pair is: " << quot(x[4],x[5]) <<endl;


    system ("pause");
    return EXIT_SUCCESS;
}
intmain()
{
//要做的事**************************
//将代码逻辑放在此注释行之后
// ***********************************************************
int x[6];
这就是你要做的。
只需将
cin>>[ctr]
更改为
cin>>x[ctr]

它位于第41行。您需要在索引
[ctr]
之前指定数组名
x
这是你的密码

我建议您使用调试器自己找出这些人为的小错误。 此外,在寻求解决方案之前,请阅读您的代码并尝试将其流程可视化

int main() 
{
    // ************************** TO DO **************************
    // Place your code logic after this comment line
    // ***********************************************************
    int x[6];
    cout<<"Enter 6 integers to divide: ";
    for(int ctr=0; ctr<6; ctr++)
    {
        cin>>x[ctr];
        if(x[ctr]==0)
        {
            cout<<"Invalid number! Please enter a non-zero value: ";
            cin>>x[ctr];
        }
    }


    cout<<"The quotient of the first pair is: " << quot(x[0],x[1]) <<endl;
    cout<<"The quotient of the second pair is: " << quot(x[2],x[3]) <<endl;
    cout<<"The quotient of the third pair is: " << quot(x[4],x[5]) <<endl;


    system ("pause");
    return EXIT_SUCCESS;
}
intmain()
{
//要做的事**************************
//将代码逻辑放在此注释行之后
// ***********************************************************
int x[6];

cout对于初学者来说,函数
quot
应该像

float quot (int num1, int num2)
{
    return static_cast<float>( num1 ) / num2;
}
输入错误。您忘记指定数组名
x

cin >> x[ctr];
此外,最好将此if语句包含在内

cin>>[ctr];
    if(x[ctr]==0)
    {
        cout<<"Invalid number! Please enter a non-zero value: ";
        cin>>x[ctr];
    }
if(x[ctr]==0)
{
coutx[ctr];
}
有一段时间,我喜欢

    while ( x[ctr] == 0 )
    {
        cout<<"Invalid number! Please enter a non-zero value: ";
        cin>>x[ctr];
    }
while(x[ctr]==0)
{
coutx[ctr];
}

对于初学者,函数
quot
的编写应如下

float quot (int num1, int num2)
{
    return static_cast<float>( num1 ) / num2;
}
输入错误。您忘记指定数组名
x

cin >> x[ctr];
此外,最好将此if语句包含在内

cin>>[ctr];
    if(x[ctr]==0)
    {
        cout<<"Invalid number! Please enter a non-zero value: ";
        cin>>x[ctr];
    }
if(x[ctr]==0)
{
coutx[ctr];
}
有一段时间,我喜欢

    while ( x[ctr] == 0 )
    {
        cout<<"Invalid number! Please enter a non-zero value: ";
        cin>>x[ctr];
    }
while(x[ctr]==0)
{
coutx[ctr];
}

cin>[ctr];
遗漏了什么?比如一个
x
cin>>x[ctr];
cin
语句可以在
循环中使用。它已经有了x:
cin>>x[ctr];
,其目的是要求用户用非零值替换任何0@儚き戦士の翼 请查看循环中的
if
语句上方。您看到了什么?或者更确切地说,您没有看到什么?可能更重要的是,请查看您发布给我们查看的内容。该代码显然缺少数组名称。谢谢大家,我没有看到第41行。我以后会更加小心
cin>[ctr]
遗漏了什么?比如可能是一个
x
cin>>x[ctr];
cin
语句可以在
中用于
循环。它已经有了x:
cin>>x[ctr];
,其思想是要求用户用非零值替换任何0@儚き戦士の翼 请查看循环中的
if
语句上方。您看到了什么?或者更确切地说,您没有看到什么?可能更重要的是,请查看您发布给我们的内容。该代码显然缺少数组名称。谢谢大家,我没有看到第41行。我以后会更加小心