mardi 15 août 2023

Hello! I have an array with a random value that keep's outputting it's address instead of a number [closed]

As the title say's I have an array with it's value randomized that won't stop outputting an address instead of number or any of the content's that it should. My problem initially was I was trying to fix an error I was getting because you can't compare with pointer's and integer's so I figured I could make the value that wasn't an array into one and that allowed me to finally run the program but overall it has only led me to this problem. I'm trying to make a game of roulette within a text adventure game so I am in fact a beginner. Here is the code related to it,

int usercash2 = usercash;

  int usercash4 = usercash;


  int ball[37] = {std::rand() % 36 + 1};//I think I solved this by simply making ball an array as well and therefore when comparing to other array's,it is not a comparison between pointer's and integer's [HYPOTHISIS]

  int r1st12[12] = {1,2,3,4,5,6,7,8,9,10,11,12};

  int r2nd12[12] = {13,14,15,16,17,18,19,20,21,22,23,24};

  int r3rd12[12] = {25,26,27,28,29,30,31,32,33,34,35,36};

  int r1_18[18] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};

  int r19_36[18] = {19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36};

  int even[18] = {2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36};

  int odd[18] = {1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35};

  int black[18] = {1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36};

  int red[18] = {2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35};

  int r1stc[12] = {1,4,7,10,13,16,19,22,25,28,31,34};

  int r2ndc[12] = {2,5,8,11,14,17,20,23,26,29,32,35};

  int r3rdc[12] = {3,6,9,12,15,18,21,24,27,30,33,36};

  int userball{1};

  int betuserball;

  
  
  
  std::cout << "WHICH NUMER WOULD YOU LIKE TO BET ON?(1-36)\n\n";


  std::cin >> userball;

  std::cout << "HOW MUCH WOULD YOU LIKE WAGER ON THAT NUMBER?\n\n";

  std::cin >> betuserball;
  

  std::cout << "HOW MUCH WOULD YOU LIKE TO WAGER ON THE FIRST 12 NUMBERS (1-12)?\n\n";

  int bet1st12;

  std::cin >> bet1st12;

  if (bet1st12 < 0 || bet1st12 > usercash){

    while(bet1st12 < 0 || bet1st12 > usercash){

      std::cout << "INVALID INPUT!\n";

      std::cin >> bet1st12;

    }

  }

  usercash4 = usercash4 - bet1st12;

  std::cout << "HOW MUCH WOULD YOU LIKE TO WAGER AND THE 2ND ROW OF 12's (13-24)\n\n";

  int bet2nd12;

  std::cin >> bet2nd12;


  if (bet2nd12 < 0 || bet2nd12 > usercash4){

    while(bet2nd12 < 0 || bet2nd12 > usercash4){

      std::cout << "INVALID INPUT!\n";

      std::cin >> bet2nd12;

    }

  } 

  usercash4 = usercash4 - bet2nd12;

  std::cout << "HOW MUCH WOULD YOU LIKE TO BET ON THE 3rd ROW OF 12'S (25-36)\n\n";

  int bet3rd12;

  std::cin >> bet3rd12;

  if (bet3rd12 < 0 || bet3rd12 > usercash4){

    while(bet3rd12 < 0 || bet3rd12 > usercash4){

      std::cout << "INVALID INPUT!\n";

      std::cin >> bet3rd12;

    }

  }

  usercash4 = usercash4 - bet3rd12;


  std::cout << "HOW MUCH WOULD YOU LIKE TO WAGER ON THE FIRST HALF OF NUMBERS?(1-18)\n\n";

  int bet1_18;

  std::cin >> bet1_18;


  if (bet1_18 < 0 || bet1_18 > usercash4){

    while(bet1_18 || bet1_18 > usercash4){

    std::cout << "INVALID INPUT!\n\n";

    std::cin >> bet1_18;

    }

  }

  usercash4 = usercash4 - bet1_18;


  std::cout << "HOW MUCH WOULD YOU LIKE TO WAGER ON THE 2ND HALF OF NUMBER'S?(19-36)\n\n";

  int bet19_36;

  std::cin >> bet19_36;

  if (bet19_36 < 0 || bet19_36 > usercash4){

    while(bet19_36 < 0 || bet19_36 > usercash4){

    std::cout << "INVALID INPUT!\n";

    std::cin >> bet19_36;

    }

  }

  usercash4 = usercash4 - bet19_36;


  std::cout << "HOW MUCH WOULD YOU LIKE TO WAGER THE BALL BEING EVEN?\n\n";

  int beteven;

  std::cin >> beteven;


  if (beteven < 0 || beteven > usercash4){

    while(beteven < 0 || beteven > usercash4){

      std::cout << "INVALID INPUT!\n";

      std::cin >> beteven;

    }

  }

  usercash4 = usercash4 - beteven;


  std::cout << "HOW MUCH WOULD YOU LIKE TO BET ON THE BALL BEING ODD?\n\n";

  int betodd;

  std::cin >> betodd;

  
  if (betodd < 0 || betodd > usercash4){

    while(betodd < 0 || betodd > usercash4){

      std::cout <<  "INVALID INPUT!\n";

      std::cin >> betodd;

    }

  }

  usercash4 = usercash4 - betodd; 


  std::cout << "HOW MUCH WOULD YOU LIKE TO WAGER ON THE BALL LANDING ON BLACK NUMBER?\n\n";

  int betblack;

  std::cin >> betblack;


  if (betblack < 0 || betblack > usercash4){

    while(betblack < 0 || betblack > usercash4){

      std::cout << "INVALID INPUT!\n";

      std::cin >> betblack;

    }

  }

  usercash4 = usercash4 - betblack;


  std::cout << "HOW MUCH WOULD YOU LIKE TO WAGER THE BALL LANDING ON RED?\n\n";

  int betred;

  std::cin >> betred;


  if (betred < 0 || betred > usercash4){

    while(betred < 0 || betred > usercash4){

      std::cout << "INVALID INPUT!\n";

      std::cin >> betred;

    }

  }

  usercash4 = usercash4 - betred;


  std::cout << "HOW MUCH WOULD YOU LIKE TO WAGER ON THE 1ST COLUMN?(please look up what that is)?\n\n";

  int bet1stc;

  std::cin >> bet1stc;


  if (bet1stc < 0 || bet1stc > usercash4){

    while(bet1stc < 0 || bet1stc > usercash4){

      std::cout << "INVALID INPUT!\n";

      std::cin >> bet1stc;

    }

  }

  usercash4 = usercash - bet1stc;


  std::cout << "HOW MUCH WOULD YOU LIKE TO WAGER ON THE 2ND COLUMN?\n\n";

  int bet2ndc;

  std::cin >> bet2ndc;


  if (bet2ndc < 0 || bet2ndc > usercash4){

    while (bet2ndc < 0 || bet2ndc > usercash4){

      std::cout << "INVALID INPUT!\n";

      std::cin >> bet2ndc;

    }

  }

  usercash4 = usercash4 - bet2ndc;

  std::cout << "HOW MUCH WOULD YOU LIKE TO WAGER ON THE 3RD COLUMN?\n\n";

  int bet3rdc;

  std::cin >> bet3rdc;


  if (bet3rdc < 0 || bet3rdc > usercash4){

    while (bet3rdc < 0 || bet3rdc > usercash4){

      std::cout << "INVALID INPUT!\n";

      std::cin >> bet3rdc;

    }

  }



  int bet6 = bet1st12 + bet2nd12 + bet3rd12 + bet1_18 + bet19_36 + beteven + betodd + bet1stc + bet2ndc + bet3rdc + betblack + betred;//jesus all that damn typing...


  std::cout << "Bartender:Finally let's roll the ball!\n\n";

  for (int i=0;i < 16;i++){

    std::cout << "TICK!\n";

  }

  std::cout << "tick\n";

  std::cout << "tick..\n";

  std::cout << "TACK!\n\n";

  std::cout << "THE BALL HAS LANDED ON " << ball << "!\n\n";

  if (ball == r1st12){

    usercash == usercash + bet1st12;

  }

  else if (r1st12 != ball){

    usercash = usercash - bet1st12;

  }


  if (ball == r2nd12){

    usercash = usercash + bet2nd12;

  }

  else if (ball != r2nd12){

    usercash = usercash - bet2nd12;

  }

  if (ball == r3rd12){

    usercash = usercash + bet3rd12;

  }

  else if (ball != r3rd12){

    usercash = usercash - bet3rd12;

  }

  if (r1_18 == ball){

    usercash = usercash + bet1_18;

  }

  else if (ball != r1_18){

    usercash = usercash - bet1_18;

  }

  if (ball == r19_36){

    usercash = usercash + bet19_36;

  }

  else if (ball != r19_36){

    usercash = usercash - bet19_36;

  }


  if (ball == black){

    usercash = usercash + betblack;

  }

  else if (ball != black){

    usercash = usercash - betblack;

  }


  if (ball == red){

    usercash = usercash + betred;

  }

  else if (ball != red){

    usercash = usercash - betred;

  }


  if (ball == even){

    usercash = usercash + beteven;

  }

  else if (ball != even){

    usercash = usercash - beteven;

  }

  if (ball == odd){

    usercash = usercash + betodd;

  }

  else if (ball != odd){

    usercash = usercash - betodd;

  }


  if (ball == r1stc){

    usercash = usercash + bet1stc;

  }

  else if (ball != r1stc){

    usercash = usercash - bet1stc;

  }


  if (ball == r2ndc){

    usercash = usercash + bet2ndc;

  }


  else if (ball != r2ndc){

    usercash = usercash - bet2ndc;

  }


  if (ball == r3rdc){

    usercash = usercash + bet3rdc;

  }


  else if (ball != r3rdc){

    usercash = usercash - bet3rdc;

  }

  int usercash3 = usercash - usercash2;

  std::cout << "$" << bet6 << " IS HOW MUCH YOU BET TOTAL!\n\n";

  std::cout << "$" << usercash2 << " IS HOW MUCH YOU HAD BEFOREHAND\n\n";

  



Aucun commentaire:

Enregistrer un commentaire