C ++乐透号码生成器

时间:2014-03-24 15:23:32

标签: c++ visual-studio-2012

我正在开发一个必须在0-9之间创建5个随机数的数组的程序,然后我必须要求用户在0-9之间输入5个数字并将其存储在和数组中,然后比较它们并表明他们是否已经把它们弄好了。我写了全部,但它一直给我这个错误

Error   1   error C1075: end of file found before the left brace '{' at 
'c:\users\bigt\documents\visual studio 2012\projects\consoleapplication2\
consoleapplication2\source.cpp(9)' 
was matched c:\users\bigt\documents\visual studio 2012\projects\
consoleapplication2\consoleapplication2\source.cpp  65  1   
ConsoleApplication2

这让我觉得我有一个逻辑错误,任何人都可以帮我找到我在这里做错的地方吗?

//#include "stdafx.h"
#include <iostream>
#include <cstdlib> 
using namespace std;

//void showValues(int[], int);

int main()
{
    const int array_size = 5;
    int numbers[array_size];
    int win_num[array_size];
    int count = 0;

    cout << "enter your altto drawing" <<endl;

    for(int i = 0; i < array_size; i++)
    {
        cin >> numbers[i];
    }

    for (int i = 0 ; i < array_size; i++)
    {
        win_num[i] = rand()%10;
    }

    for (int i =0; i < array_size; i++)
    {
        if (numbers[i] != win_num[i])
        {
            cout << "sorry try again" << endl;
        }
        else 
        {
            count++;
        }
    if (count == 5)
    {
        cout << " you win" << endl;
    }
    else
    {
        cout << " you did not win, you had" << count << "right numbers" << endl;
    }
    cout << "the winning numbers are" << endl;

    for( int i = 0; i < array_size ; i ++)
    {
        cout << win_num[i] << " ";
    }

    system ("pause");
    return 0;
}

2 个答案:

答案 0 :(得分:4)

你错过了一次关闭}

for (int i =0; i < array_size; i++)
{
    if (numbers[i] != win_num[i])
    {
        cout << "sorry try again" << endl;
    }
    else 
    {
        count++;
    }
}//^^this one is missing

答案 1 :(得分:1)

您尚未关闭第三个for循环的块。