Thread: I need some help

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    1

    I need some help

    I need some help.

    Write a program that simulates a lottery. The program should have an array of 5 integersnamed
    winningDigits, with a randomly generated number in the range of 0 through 9for each element in the array. The program should ask the user to enter 5 digits and shouldstore them in a second integer array named player. The program must compare the corre-sponding elements in the two arrays and count how many digits match. For example, thefollowing shows the winningDigits array and the Player array with sample numbersstored in each. There are two matching digits, elements 2 and 4.


    WinningDigits 7 4 1 9 3 player 4 2 9 7 3 Once the user has entered a set of numbers, the program should display the winning digitsand the player’s digits and tell how many digits matched.









    Here's what I have so far. It won't work and I'm not sure why.

    Code:
    #include <iostream>
    
    
    int main()
    {
    
    
    int  WinningDigits[5];
    int Player[5];
    int SameValue[5];
    int length;
    int counter = 0;
    
    
    for(int j = 0; j<5;++j) //fill up the Winning Digits
    WinningDigits[i];
    
    
    for(int i = 0; i<5;++i) //randomly generate numbers in the Player
     Player[i] = rand()%10 ; //generate numbers between 0 and 9
    
    
    
    
    
    cout<<"DISPLAY RESULT:"<<end;
    cout<<=============================================<<endl;
    for(int d = 0;d<5;++d)
    {
    cout<<"the elements of the WinningDigits are:"<<WinningDigits[d]<<endl;
    cout<<"the elements entered by player are:"<<Player[d]<<endl;
    
             If(Player[d]==WinningDigits[d])
             {
             cout<<"the number"<<player[d]<<"is correct"<<endl; 
             SameVal[counter] = player[d];
             counter++;
             }
    
    }
    
             for(int u  = 0;u<counter; ++u)
             cout<<SameVal[u]<<endl;
    
    
    
    return 0;
    }
    
    


  2. #2
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463
    Code:
    for(int j = 0; j<5;++j) //fill up the Winning Digits
    WinningDigits[i];
    "i" was not declared in the for loop scope, switch it to "j".

    Code:
    cout<<"DISPLAY RESULT:"<<end;
    there is no "end" in the iostream lib, change it to "endl".

    stick "using namespace std;" right after include<iostream>. This is the easiest way to access name space std.

    Code:
    cout<<=============================================<<endl;
    put the "===============" in a pair of quotes.

    You used rand() without seeding it first. To seed rand you will need to include "cstdlib". Also, you should read prelude's article on rand: http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx .

    Code:
    If(Player[d]==WinningDigits[d])
    ...
    cout<<"the number"<<player[d]<<"is correct"<<endl; 
             SameVal[counter] = player[d];
    there is no "If" in c/c++; the "i" should be lowercase. C++ is case sensitive. So you also have a problem with "Player" and "player"

    Your compiler's errors regarding these exceptions should be very straight forward to understand. Practice reading the compiler's errors to debug your code is essential in learning C++.
    Last edited by nimitzhunter; 04-04-2013 at 10:21 PM.
    "All that we see or seem
    Is but a dream within a dream." - Poe

Popular pages Recent additions subscribe to a feed