|
#1
|
|||
|
|||
|
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 () { } |
|
#2
|
|||
|
|||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|