The computer will generate six numbers between 1-40 inclusive.
Then i will have to bet six numbers between 1-40 inclusive
If I get all the six numbers correct, I win the jackpot
If I get five correct numbers, I win RS 10000
If I get four correct numbers, I win RS 4500
and finally if I get three correct numbers, I win RS 100
I want to know what are the codes should I need and how to generate the numbers.
Can someone help me to solve this?? (The code will be written in C program)
Thnks
15 replies to this topic
#1
Posted 08 November 2011 - 08:42 AM
|
|
|
#2
Posted 08 November 2011 - 08:54 AM
rand()%41 - this command will generate random numbers(from 1 to 40) - you have to save them into an array.
scanf(); - use this to read the numbers,then just check if the pressed number is into the array.
scanf(); - use this to read the numbers,then just check if the pressed number is into the array.
#3
Posted 08 November 2011 - 09:19 AM
alex1 said:
rand()%41 - this command will generate random numbers(from 1 to 40) - you have to save them into an array.
I think you forgot about '+'. In my opinion rand() % 40 +1 will generate random numbers from 1 to 40.
As for the main toppic. It would be nice to see what have you done so far.
Basicly you need 2 arrays one for a user to fill and one for program to fill with random numbers. Then compare arrays and finally check how many numbers in first array matches second array. Also You might want to check If User or Program didn't put two the same numbers.
#4
Posted 08 November 2011 - 09:59 AM
Ya, i have understand the concept but I don't know
how to write the codes that why I want someone to help me
in writing the codes??
how to write the codes that why I want someone to help me
in writing the codes??
#5
Posted 08 November 2011 - 11:07 AM
Someone else posted the exact same problem in this thread. You may want to look there, as well.
#6
Posted 09 November 2011 - 04:46 AM
kirikou2 said:
The computer will generate six numbers between 1-40 inclusive.
Then a player will have to bet six numbers between 1-40 inclusive
If he gets all the six numbers correct, he wins the jackpot
If he gets five correct numbers, he wins RS 10000
If he gets four correct numbers, he wins RS 4500
and finally if he gets three correct numbers, he wins RS 100
The program is below, the fact is when the six numbers which I entered sometime matches
completely to the generated number by the computer but it does not display any prices even
for five,four or three correct numbers
Can someone help me to solve this??
Thnks
Then a player will have to bet six numbers between 1-40 inclusive
If he gets all the six numbers correct, he wins the jackpot
If he gets five correct numbers, he wins RS 10000
If he gets four correct numbers, he wins RS 4500
and finally if he gets three correct numbers, he wins RS 100
The program is below, the fact is when the six numbers which I entered sometime matches
completely to the generated number by the computer but it does not display any prices even
for five,four or three correct numbers
Can someone help me to solve this??
Thnks
#include <stdlib.h>
#include <stdio.h>
int main()
{
int numContainer[6];
int theBet[6];
int count = 0; //for counting the same number
//this is for the player to bet six number
int i;
printf("Please bet 6 numbers in the range 1-40: ");
scanf("%d",&numContainer[6]);
printf("\n");
//this is for the number generator
for(i=0;i<6;i++)
{
theBet[i] = (rand()%40)+1;
printf("%d: ",theBet[i]);
}
int j;
//checking numbers, if there is a same number then add to count
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
if(numContainer[i] == theBet[j])
{
count++;
}
}
}
//the prize for how many same numbers
if(count == 6)
{
printf("Win Jackpot!!");
}
else if(count == 5)
{
printf("Win RS 10000");
}
else if(count == 4)
{
printf("Wind RS 4500");
}
else if(count == 3)
{
printf("Win RS 100");
}
system("PAUSE");
return(0);
}
#7
Posted 09 November 2011 - 05:06 AM
printf("Please bet 6 numbers in the range 1-40: ");
scanf("%d",&numContainer[6]);
printf("\n");
This should be inside a loop,because now the numcontainer have just 1 proper value inside.
somthing like:
for(i=0;i<6;i++){
printf("Please bet the %d number between 1-40: ",i+1);
scanf("%d",&numContainer[i]);
printf("\n");
}
You're on a good way!
#8
Posted 09 November 2011 - 07:49 AM
Quote
The code do work. Now I have created additional code such that a bet costs Rs 20
and a player can bet as many time as he wishes. Then the total cost of the bet is displayed.
The problem which am encountered here is that, suppose I bet 3 time, then the program
should allow me to bet six numbers three time, but in this case the program allows me to bet only one time!!
How to solve this???
and a player can bet as many time as he wishes. Then the total cost of the bet is displayed.
The problem which am encountered here is that, suppose I bet 3 time, then the program
should allow me to bet six numbers three time, but in this case the program allows me to bet only one time!!
How to solve this???
#include <stdio.h>
#include <stdlib.h>
int main()
{
int numContainer[6];
int theBet[6];
int count = 0; //for counting the same number
int i,e,f;
printf("How many time you want to bet:");
scanf("%d",&e);
f=e*20;
printf("Your total cost is: %d\n",f);
printf("\n");
//this is for the player to bet six number
for(i=0;i<6;i++){
printf("Bet six numbers between 1-40: ",i+1);
scanf("%d",&numContainer[i]);
printf("\n");
}
for(i=0;i<6;i++){
theBet[i] = (rand()%40)+1;
printf("%d: ",theBet[i]);
}
//checking numbers, if there is a same number then add to count
int j;
for(i=0;i<6;i++){
for(j=0;j<6;j++){
if(numContainer[i] == theBet[j])
{
count++;
}
}
}
//the prize for how many same numbers
if(count == 6)
{
printf("You Win the JACKPOT!!\n");
printf("\n");
}
else if(count == 5)
{
printf("You Win RS 10000\n");
printf("\n");
}
else if(count == 4)
{
printf(" You win RS 4500\n");
printf("\n");
}
else if(count == 3)
{
printf("You win RS 100\n");
printf("\n");
}
else if(count<3)
{
printf("Sorry,You Lose\n");
printf("\n");
}
system("PAUSE");
return 0;
}
#9
Posted 09 November 2011 - 08:36 AM
for(i=0;i<6;i++){
printf("Bet six numbers between 1-40: ",i+1);
scanf("%d",&numContainer[i]);
printf("\n");
}
now the i+1 into the printf is useless :cool:
#10
Posted 09 November 2011 - 08:56 AM
Even though I have removed the i+1 in the printf
it does not work
for example if i want to bet 3 time, the program should allow me to enter six numbers
3 times but it doesn't despite i have removed the i+1
How to solve this now???
it does not work
for example if i want to bet 3 time, the program should allow me to enter six numbers
3 times but it doesn't despite i have removed the i+1
How to solve this now???
#11
Posted 09 November 2011 - 09:07 AM
for(i=0;i<e;i++){
printf("Bet numbers between 1-40: ");
scanf("%d",&numContainer[i]);
printf("\n");
}
it was:
for(i=0;i<6;i++)since you say i<6 - isn't it logic to make 6 loops?You need to replace the 6 with the number entered by the user - at your case the loop should be done e times.
Try to read the code line by line and you will find the solutions.
#12
Posted 10 November 2011 - 05:55 AM
Now, Every time when am compiling the program below it always generate the same
random numbers that is 2 28 15 21 10 5
How to make the program generate other numbers??
random numbers that is 2 28 15 21 10 5
How to make the program generate other numbers??
#include <stdlib.h>
#include <stdio.h>
int main()
{
int numContainer[6];
int theBet[6];
int count = 0; //for counting the same number
int i,e,f;
printf("How many time you want to bet:");
scanf("%d",&e);
f=e*20;
printf("Your total cost is: Rs %d\n",f);
printf("\n");
//this is for the player to bet six number
for(i=0;i<6;i++){
printf("Bet six numbers between 1-40: ");
scanf("%d",&numContainer[i]);
printf("\n");
}
for(i=0;i<6;i++){
theBet[i] = rand()%40+1;
printf("%d:",theBet[i]);
}
//checking numbers, if there is a same number then add to count
int j;
for(i=0;i<6;i++){
for(j=0;j<6;j++){
if(numContainer[i] == theBet[j])
{
count++;
}
}
}
//the prize for how many same numbers
if(count == 6)
{
printf("You Win the 25Million JACKPOT!!\n");
printf("\n");
}
else if(count == 5)
{
printf("You Win RS 10000\n");
printf("\n");
}
else if(count == 4)
{
printf(" You win RS 4500\n");
printf("\n");
}
else if(count == 3)
{
printf("You win RS 100\n");
printf("\n");
}
else if(count<3)
{
printf("Sorry,You Lose\n");
printf("\n");
}
system("PAUSE");
return(0);
}
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









