I have to make a card game like HiLo where you enter your cash amount, you get two cards, and then you bet. if the third randomly generated card is between the other two, you add that money to your total and if its not you lose that money. One thing the code is supposed to do is if you don't like the two cards you are given at the beginning you should be able to enter 0 and they give you new cards. My biggest problem comes from when I enter 0 it gives me two new cards and then asks how much I want to put up and when I enter that number it basically ignores the new bet money and asks me again. essentially i have to write twice the betmoney for it to work, how do I fix that.
using System;
//find how to print dollar signs
class MainClass {
public static void Main (string[] args) {
var rnd = new Random();
int card1, card2, card3;
int playermoney = 0;
int betmoney = 0;
string exit = "";
Console.WriteLine("HiLo Card Game");
Console.Write("Enter the starting cash amount: $");
playermoney = Convert.ToInt32(Console.ReadLine());
while(exit!="n"){
card1 = rnd.Next(1,15);
card2 = rnd.Next(1,15);
Console.WriteLine("Cash balance is ${0}",playermoney);
Console.WriteLine("{0} - {1}", card1, card2);
Console.Write("The amount you want to bet? ");
betmoney = Convert.ToInt32(Console.ReadLine());
if (betmoney>=0){
if (betmoney == 0){
Console.WriteLine("Cash balance is ${0}",playermoney);
Console.WriteLine("{0} - {1}", rnd.Next(1,15), rnd.Next(1,15));
Console.Write("The amount you want to bet? ");
betmoney = Convert.ToInt32(Console.ReadLine());
continue;
}//end if 0
card3 = rnd.Next(1,15);
Console.WriteLine("Your card is a {0}", card3);
if(card1<card2){
if((card3>card1 && card3<card2)){
playermoney = playermoney+betmoney;
Console.WriteLine("WINNER! New Balance is {0}", playermoney);
}//end winner if
else{
playermoney = playermoney-betmoney;
Console.WriteLine("LOSER! New Balance is {0}", playermoney);
if (playermoney<0){
Console.WriteLine("--------------");
Console.WriteLine("game over");
break;
}//end negative if
}//end else loser
}
if (card1>card2){
if(card3>card2 && card3<card1){
playermoney = playermoney+betmoney;
Console.WriteLine("WINNER! New Balance is {0}", playermoney);
}
else{
playermoney = playermoney-betmoney;
Console.WriteLine("LOSER! New Balance is {0}", playermoney);
if (playermoney<0){
Console.WriteLine("--------------");
Console.WriteLine("game over");
break;
}//end negative if
}//end else loser
}
}
else{
Console.WriteLine("--------------");
Console.WriteLine("game over");
break;
}
Console.Write("Play Again? <y/n> ");
exit = Console.ReadLine();
Console.Clear();
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…