Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.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++ C++;尝试退出xcode中的程序时出现11db错误。初级水平_C++_Xcode_Do While - Fatal编程技术网

C++ C++;尝试退出xcode中的程序时出现11db错误。初级水平

C++ C++;尝试退出xcode中的程序时出现11db错误。初级水平,c++,xcode,do-while,C++,Xcode,Do While,我正在开始回答彩票硬件问题,但是,当我调用getLottoPicks函数时,它会抛出一个11db错误的程序。因此,当程序第一次运行时,您使用“q”或“q”退出时,它会工作,但是如果用户通过该程序一次,然后尝试退出,则会出现11db错误。我试着在各种地方粘贴cin.ignore(),但都没用 #include <iostream> #include <iomanip> #include <cmath> #include <cstdlib> #incl

我正在开始回答彩票硬件问题,但是,当我调用getLottoPicks函数时,它会抛出一个11db错误的程序。因此,当程序第一次运行时,您使用“q”或“q”退出时,它会工作,但是如果用户通过该程序一次,然后尝试退出,则会出现11db错误。我试着在各种地方粘贴cin.ignore(),但都没用

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cctype>

using namespace std;

void menu();
int getLottoPicks(int[], int);

int main()
{
    char choice;
    const int SIZE = 6;
    int UserTicket[SIZE];
    int WinningNums[SIZE];
    string name;

    do
    {
        menu();
        cin  >> choice;
        cout << endl;
        cin.ignore();

        switch (choice)
        {
            case '1':
                cout << "Please enter your name: ";
                getline(cin, name);

                getLottoPicks(UserTicket,SIZE);

                for(int i = 0; i <= SIZE; i++)
                {
                    cout << UserTicket[i];
                    cout << ", ";
                }
                cout << endl <<endl;
                break;
            case 'q':
            case 'Q':
                cout << "You have chosen to quit the program. Thank you for using!\n";
                break;
            default:
                cout << "Invalide Selection.\n";
                break;
        }

    }while (choice != 'q' && choice != 'Q');

    return 0;
}

void menu()
{
    cout << "1) Play Lotto\n";
    cout << "q) Quit Program\n";
    cout << "Please make a selection: \n";
}

int getLottoPicks(int nums[], int size)
{
    cout << "Please enter your 7 lotto number picks between 1 and 40.\n";

    for(int i = 0; i <= size; i++)
    {
        cout << "Please pick #" << i + 1 << ": ";
        cin  >> nums[i];
        cout << endl;
    }
    return nums[0], nums[1], nums[2], nums[3], nums[4], nums[5], nums[6];
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
无效菜单();
int getLottoPicks(int[],int);
int main()
{
字符选择;
常数int SIZE=6;
int UserTicket[SIZE];
int WinningNums[大小];
字符串名;
做
{
菜单();
cin>>选择;

cout问题出在函数
getLottoPicks

首先指出一个设计问题:您以某种方式调用此函数以从用户获取7个输入,但您错误地从参数
nums
返回了7个元素(在您的情况下,这导致函数从仅包含6个元素的数组访问第7个元素)。此外,您已经通过将值存储在
nums
参数中来获取这些值。将
getLottoPicks
返回类型更改为
void
,并删除
返回nums[0]、nums[1]、nums[2]、nums[3]、nums[4]、nums[5]、nums[6];


第二,您使用条件退出for循环错误。C++中的数组由0开始的索引访问。

是调试器的命令提示符,而不是错误代码。您的程序已崩溃,可能是因为您正在将7个元素加载到一个大小为6的数组中。

11db error
这是什么?如果有错误消息,请编辑问题帖子中错误消息的确切文本。它只显示11db,不会结束程序。a side选项卡在x代码中打开,带有libsystem_kernel.dylib`_pthread_kill:0x7fff65d232bc:movl$0x20000148,%eax;imm=0x20000148 0x7fff65d232c1:movq%rcx,%r10 0x7fff65d232c4:syscall->0x7fff65d232c6:jae 0x7fff65d232d0;0x7fff65d232c8:movq%rax,%rdi 0x7fff65d232cb:jmp 0x7FFF65D157;CrrRoRoNoC取消0x7FFF6D22D0:ReqQI认为它与开关实例1中的函数调用有关:当我评论程序退出时,成功地感谢您添加了附加上下文。我不使用<代码> XCOD/<代码>,在25到30年中,我已经在C++中编程了,我没有看到一个错误代码。11db错误。
for(int i=0;我非常感谢!这样做并不是在
for循环中“返回”任何内容。
元素,它实际上是只有6个元素的数组的第7个元素。太好了!再次感谢。我将const int SIZE=7更改为for(int i=0;i