Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > C++

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 11-04-2009, 04:25 PM
fantasyfootball fantasyfootball is offline
Registered User
 
Join Date: Oct 2009
Posts: 9
using arrays and for functions

Here is the question:
Your state is in a process of creating a weekly lottery. Once a week, five distinct random intergers between 1 to 40 (inclusive) are drawn. If a player guesses all the numbers correctly, the player wins a certain amount. Write a program that does the follwing:

A. Generates five distinct random numbers between 1 and 40 (inclusive) and stores them in an array.
B. Sorts the array containing the lottery numbers.
C. Prompts the player to select five distinct integers between 1 and 40 (inclusive) and stores the numbers in an array. The player can select the numbers in any order and the array containing the numbers need not be sorted.
D. Determines whether the player guessed the lottery numbers correctly. If the player guessed the lottery numbers correctly, it outputs the message "You win!"l; otherwise it outputs the message "You lose!" and outputs the lottery numbers.
Your program should allow a player to play the game as many times as the players wants to play. Before each play, generate a new set of lottery numbers.
You are required to use functions to organize your code. Below is the algorithm of the main function, where many steps are calling functions. Code your program accordingly.


HERE IS WHAT I GOT DONE SO FAR

#include <iostream>
#include <iomanip>
using namespace std;
void generate (int []);
void sort (int []);
void get (int []);
string check (int [], int []);
char answer ();

int main()
{
/*
1. Call function to ask user whether user likes to play lottery; the answer must be y, Y or n, N
2. As long as user answer is Y, repeat the following:
a. call function to generate lottery number array
b. call function to sort the lottery number array
c. call function to get the number array the player pick
d. call function to check if the numbers user picked match the lottery numbers
e. if they all match, output “You Win!”
f. otherwise, output “You Lose.”
g. Call function to ask user whether he/she likes to play lottery; the answer must be y, Y or n, N
*/
int guess[5];
int num40[5];
char YN;
string winOrLose;

YN = answer();
while(YN='Y')
{
generate(num40);
sort(num40);
get(guess);
winOrLose= check(guess, num40);
cout << winOrLose;
YN= answer();
}
getch();
return 0;
}
void generate (int num40[])
{
for(int i = 0; i < 5;i++)
{
num40[i]= rnd * 40 + 1;
}
}
void sort (int number[])
{
for(
}
void get (int number[])
{
}
string check (int picked[], int value[])
{
}
char answer ()
{
}
Reply With Quote
  #2  
Old 11-05-2009, 04:50 PM
jonnin jonnin is offline
Senior Member
 
Join Date: Dec 2003
Posts: 3,008
You are posting too much stuff that is not even really attempted.

Give it a better try and ask for help again later, you can do better than just making empty functions.

I will give you a hint:
the easiest sort to write while keeping a decent run speed is shell sort. You can look that up on wikipedia and it gives the algorithm. Its only a few lines of code (but a very complex and powerful algorithm). If you dont care for that, the brute force sorts (bubble sort) are the same amount of code but take exponentially more time to run -- but easy to understand how they work. You can get that algorithm on wikipedia too.

Last edited by jonnin; 11-05-2009 at 04:55 PM.
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 08:15 AM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.