3 Replies - 370 Views - Last Post: 24 March 2013 - 08:37 PM Rate Topic: -----

#1 shuhei69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-March 13

guessing game with points

Posted 23 March 2013 - 02:20 AM

hi guys, im having a problem with this..
output should be..
how many points would you like. then the guesses choices.
enter your choice?
point at risk.
if the number is right then,the risk point will be added, if wrong then subtract.
problem is dont know how to add or subtract from the points.
my code so far..
#include<stdio.h>
#include<conio.h>
#include <time.h>
#include <stdlib.h>

main() 
{
srand(time(NULL));

int guess,r,guesses;
int points=0,n;

printf("How many points would you like? ");
scanf("%d",&points);

char option, go;
int array[5],i;

printf("\nGuesses Choices \n");
printf("O-Odd \t\t[01-35]\nE-Even\t\t[02-36] \nL-Low \t\t[01-12] \nM-Medium \t[13-24] \nH-High \t\t[25-36] \nN-Number\t[01-36]\n");
printf("\nGuess Limit is 5");
printf("\nHow many guesses would you like? ");
scanf(" %d",&guesses);

for(i=0;i<guesses;i++){
printf("\nGuess %d",i+1);

printf("\nEnter your choice: ");
scanf(" %c", &option);

switch (option) {

case 'O':
case 'o':    
     odd();break;

case 'E':
case 'e':
    even();break;

case 'L':
case 'l':
    low();break;

case 'M':
case 'm':
     medium();break;

case 'H':
case 'h':
     high();break;
     
case 'F':
case 'f':
     
printf("Left\n");
break;

case 'C':
case 'c':
printf("Center\n");
break;

case 'R':
case 'r':
printf("Right\n");
break;

case 'N':
case 'n':
   number();break;
default:
printf("Try again!\n");

scanf(" %d",array[i]);
}
}

getch();
}



int odd(int guess,int r,int points)
{
    int b =1+(2*rand ()) %36,an,b1,b2;
    
     printf("enter number: ");
     scanf("%d",&guess);
     printf("Point at risk? ");
     scanf("%d",&r);



     if(guess<b || guess>B)/>/>{
                an=b;
     printf("Winning number is : %d",an);
                b1=r;
                printf("\nYou lost %d point(s).\n",b1);   
                }              
                if(guess==B)/>/>
                {
                an=b;
     printf("Winning number is : %d",an);
                b2=r+r;                
                printf("plus point/s:%d \n",b2);}
         
}

int even(int guess,int r)
{
    int c =2+(2*rand ()) %36,an2,c1,c2;
    
     printf("enter number: ");
     scanf("%d",&guess);
     printf("Point at risk? ");
     scanf("%d",&r);
     if(guess<c || guess>c){
                an2=c;
     printf("Winning number is : %d",an2);
                c1=r;
                printf("\nYou lost %d point(s).\n",c1);
                }              
                if(guess==c)
                {
                c2=r+r;                
                printf("plus point/s:%d \n",c2);}
}

int low(int guess,int r)
{
    int l=rand() % 12+1,l2,l3,ans1;
    
     printf("enter number: ");
     scanf("%d",&guess);
     printf("Point at risk? ");
     scanf("%d",&r);

     if(guess<l || guess>l){
                ans1=l;
     printf("Winning number is : %d",ans1);
                l2=r;
                printf("\nYou lost %d point(s).\n",l2);
                }

                
                if(guess==l)
                {
                l3=r+r;                
                printf("plus point/s:%d \n",l3);}
}

int medium(int guess,int r)
{
    int m=rand() % 12+13,m2,m3,ans2;
    
     printf("enter number: ");
     scanf("%d",&guess);
     printf("Point at risk? ");
     scanf("%d",&r);


     if(guess<m || guess>m){
                ans2=m;
     printf("Winning number is : %d",ans2);
                m2=r;
                printf("\nYou lost %d point(s).\n",m2);
                }

                
                if(guess==m)
                {
                m3=r+r;                
                printf("plus point/s:%d\n",m3);}
}

int high(int guess,int r)
{
    int h=rand() % 12+25,h2,h3,ans3;
    
     printf("enter number: ");
     scanf("%d",&guess);
     
     printf("Point at risk? ");
     scanf("%d",&r);

     if(guess<h || guess>h){           
                 ans3=h;
     printf("Winning number is : %d",ans3);
                h2=r;
                printf("\nYou lost %d point(s).\n",h2);
                }

                
                if(guess==h)
                {
                h3=r+r;                
                printf("plus point/s:%d \n",h3);}
}

int number(int guess,int r)
{
   int number = rand() % 36,ans,p,t;
   
     printf("enter number: ");
     scanf("%d",&guess);
     printf("Point at risk? ");
     scanf("%d",&r);

     if(guess<number || guess>number){
     ans=number;
     printf("Winning number is : %d",ans);
     
                p=r;
                printf("\nYou lost %d point(s).\n",p);
                }               
                if(guess==number)
                {
                 t=r+r;                
                 printf("plus point/s:%d \n",t);}
}






Is This A Good Question/Topic? 0
  • +

Replies To: guessing game with points

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,494
  • Joined: 05-May 12

Re: guessing game with points

Posted 24 March 2013 - 05:33 PM

On first glance, it looks like you aren't passing any parameters to your functions.
Was This Post Helpful? 0
  • +
  • -

#3 shuhei69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-March 13

Re: guessing game with points

Posted 24 March 2013 - 05:48 PM

View PostSkydiver, on 24 March 2013 - 05:33 PM, said:

On first glance, it looks like you aren't passing any parameters to your functions.


like for example? sorry beginner. but the prog is running, the problem is to add or subtruct the risk on points.
Was This Post Helpful? 0
  • +
  • -

#4 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1432
  • View blog
  • Posts: 4,968
  • Joined: 19-February 09

Re: guessing game with points

Posted 24 March 2013 - 08:37 PM

You should have prototypes before main eg.

int odd(int guess, int r, int points);



You could return the new value of points using the return statement of the function.

 points = odd(guess, r, points);

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1