I have a question, how can i use two different sets else if statements that will work properly? i tried it normally but the second set of else if statements dont work at all. please help. thanks

post your code so we can see what you did,

how to post it here? sorry i am just new in this forum.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
  int iBet,Random1,Random2;
  char red,blue,green,yellow,white,pink;
  char cColor;
  clrscr();
  printf("Enter the color you want to bet\n 1 for Red\n 2 for Blue\n 3 for Green\n 4 for Yellow\n 5 for White\n 6 for Pink : ");
  scanf(" %c",&cColor);
  printf("How much will you bet? :   ");
  scanf(" %d",&iBet);
  randomize();
  Random1=random(2);
  { if(Random1==1)
    puts("\n\n1st color: Red");
  else if(Random1==2)
    puts("\n\n1st color: Blue");
  else if(Random1==3)
    puts("\n\n1st color: Green");
  else if(Random1==4)
    puts("\n\n1st color: Yellow");
  else if(Random1==5)
    puts("\n\n1st color: White");
  else if(Random1==6)
    puts("\n\n1st color: Pink");
  }//rand if
  if(Random1==1&&cColor==1)
    puts("You win!");
  else if(Random1==2&&cColor==2)
    puts("You win!");
  else if(Random1==3&&cColor==3)
    puts("You win!");
  else if(Random1==4&&cColor==4)
    puts("You win!");
  else if(Random1==5&&cColor==5)
    puts("You win!");
  else if(Random1==6&&cColor==6)
    puts("You win!");
  else
    puts("\nBetter luck next time.");
  getch();
}

hey the random(2) their it should be random(7) i just forgot to change it. thanks

anyone can help?

Theres Lots of unnecessary/uninitialized variables found in the code.

next here's the proper way of using the rand() function

  /* initialize random seed: */
  srand ( time(NULL) );

  /* generate number ranging from 1 - 7 */
  Random1 = rand() % 7 + 1; 

So what does it do wrong? To get help you need to post details, not just a vague "it doesn't work" message. We need to know how it fails in order to understand what "doesn't work" means.

also the following code is done wrong:

    printf("Enter the color you want to bet\n 1 for Red\n 2 for Blue\n 3 for Green\n 4 for Yellow\n 5 for White\n 6 for Pink : ");
    scanf(" %c",&cColor);

you want the user to input an integer yet your storing it in a character variable and later comparing the character variable to an integer

Either change :
char cColor;
scanf(" %c",&cColor);

to
int cColor;
scanf(" %d",&cColor);

OR

change all your conditions as follows:
else if(Random1==1&&cColor=='1')

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.