I actually was on the right track with coin toss:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlayCoinToss
{
class Program
{
static void Main(string[] args)
{
string user;
int user1; // User 1 is the input--what I'm selecting
Random numberGenerator = new Random();
bool playAgain = true;
string userChoice;
string houseChoice;
int house;
string outcome;
//Below I'm changing what the console looks like:
// set background to white
Console.BackgroundColor = ConsoleColor.White;
// set foreground to blue
Console.ForegroundColor = ConsoleColor.Red;
// clear the screen
Console.Clear();
//greeting players
Console.WriteLine("The user is betting against the house");
while (playAgain == true)
{
Console.Write("Please Make Your Selection (1 = Heads and 2 = Tails): ");
user = Console.ReadLine();
house = numberGenerator.Next(1, 3);
while (!int.TryParse(user, out user1) || user1 <= 0 || user1 >= 3) //this is the houses selection. I'm going to be betting against the house
{
Console.Write("Please Make Your Selection (1 = Heads and 2 = Tails): ");
user = Console.ReadLine();
}
//below are the rules for me the player
if (user1 == 1)
{
userChoice = "Heads";
}
else
{
userChoice = "Tails";
}
//below are the rules for me the house --or whatever I'm playing against
if (house == 1)
{
houseChoice = "Heads";
}
else
{
houseChoice = "Tails";
}
//Below I have to figure out who wins and who loses instances of this game
if (house == user1)
{
outcome = "lose"; //if there is a tie then no money is won or lost
}
//need to put how I lose here
else
{
outcome = "win";
}
//Below I have to figure out how to print results and if they want to play again
Console.Write("You chose " );
Console.Write(userChoice);
Console.Write(", the house chose ");
Console.Write(houseChoice);
Console.Write("You ");
Console.Write(outcome);
Console.WriteLine("Do you want to play again? (yes/exit)");
user = Console.ReadLine();
while (user != "YES" && user != "yes" && user != "EXIT" && user != "exit") //They can input all caps or all lowercase since I wrote it this way
{
Console.WriteLine("Error Please enter yes or exit");
user = Console.ReadLine();
}
if (user == "YES" || user == "yes")
{
playAgain = true;
}
else
{
playAgain = false; //the only important thing is that they enter yes
}
}
}
}
}
I kind of started getting confused reading the requirements after that. Then I repurposed a menu here
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
const int maxMenuItems = 4
;
int selector = 0;
bool good = false;
while (selector != maxMenuItems)
{
Console.Clear();
DrawTitle();
DrawMenu(maxMenuItems);
good = int.TryParse(Console.ReadLine(), out selector);
if (good)
{
switch (selector)
{
case 1:
Console.WriteLine("// code for case 1 here");
break;
case 2:
Console.WriteLine("// code for case 2 here");
break;
case 3:
Console.WriteLine("// code for case 3 here");
break;
case 4:
Console.WriteLine("Exit");
break;
default:
if (selector != maxMenuItems)
{
ErrorMessage();
}
break;
}
}
else
{
ErrorMessage();
}
Console.ReadKey();
}
}
private static void ErrorMessage()
{
Console.WriteLine("Typing error, press key to continue.");
}
private static void DrawStarLine()
{
Console.WriteLine("************************");
}
private static void DrawTitle()
{
DrawStarLine();
Console.WriteLine("+++ Lets Play a Game +++");
DrawStarLine();
}
private static void DrawMenu(int maxitems)
{
DrawStarLine();
Console.WriteLine(" 1. Add Funds");
Console.WriteLine(" 2. Coin toss");
Console.WriteLine(" 3. Roulette");
Console.WriteLine(" 4. Exit program");
DrawStarLine();
Console.WriteLine("Make your choice: type 1, 2, 3, 4", maxitems);
DrawStarLine();
}
}
}
and now I have managed to totally confuse myself and I'm lost. Please please help

Aman JainPosted Jun 14, 2013, 5:30 AM
using System;
Aman JainPosted Jun 21, 2013, 12:43 AM
1. We can create a table. some stored procedures to insert and search.
2. On the main menu(welcome user), we can add Login and Register option.
3. Login will use the search query and get the user signed in and use the funds and at the exit, save the updated amount.
4. Register option will take a username, search if it already exists. stores a password and takes the initial amount as 100 (by default).
5. If this works well, then we can try adding a "Hello
CarolynPosted Jun 19, 2013, 9:22 AM
removed: int amount=100 in each of the the betting sections.
added:
while (amount < bet)
{
Console.WriteLine("You are exceeding your fund's limit, Please add funds before you bet.");
Funds();
}
Force User To Add More Funds:
playAgain = true;
break;
Didn't need to call Check()
I would love to take this to the next level. I have used MYSQL in the past so I should be able to follow along. I think this exercise will help a lot of people. There are some great YouTube videos out there but nothing beats a step by step approach the way we did it.
Would we start by going to SQL Server and creating a table that is something like this:
CREATE TABLE User
(
UserID int,
UserName varchar(100),
Password varchar(100),
Funds decimal(19,4)
);
Aman JainPosted Jun 19, 2013, 1:16 AM
Also, while I executed your code, at few places I have edited to make it a bit more user friendly.
For adding user profiles, i think it will need a database where a user can store the amount he won and next time he enters the game, he is having that amount. it will also need a login, so that only he can use that money.
If u r willing, i'll sure help u in that also.
But for now, I think your task is completed. Here is the code:
CarolynPosted Jun 18, 2013, 4:28 PM
I added the case 1 by modifying your Win Lose condition!
One last question my funds area doesn't cascade into the other games. How would we change int amount = 100; to act more like a bank that uses the amount in Funds() ?
User Profiles aren't one of my requirements for the project but you have me curious. How would we begin to set that up?
CarolynPosted Jun 18, 2013, 1:00 PM
again = Console.ReadLine().ToUpper();
if (again == "YES")
{
playAgain = true;
}
else if (again == "NO")
to this
and it works perfect. I'll get cracking on the other pieces of the game. Be back soon!!
Aman JainPosted Jun 18, 2013, 12:18 AM
The code I send in my last post has betting part. I think first you should add this (betting part) in your roulette number and color game also, same as done in toss game. If it works fine, then we can make it more advanced.
If you find any difficulty in doing this, feel free to ask.
Regards,
Aman
CarolynPosted Jun 17, 2013, 7:16 PM
CarolynPosted Jun 17, 2013, 7:02 PM
You have been very helpful in letting me see the logic.
Aman JainPosted Jun 17, 2013, 3:19 AM
Hope this helps you.
Suggestion: You can add user profiles, so that one user can use same amount he won/made in one game, to bet in other games. #Interesting #Catchy
private static void Play()
{
//===This is the user inputting their choice===
int user1;
//===This is what makes the output random===
Random numberGenerator = new Random();
string userChoice;
string again;
string houseChoice;
int house;
string outcome;
//===This makes the game easier on the eyes===
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Blue;
Console.Clear();
Console.WriteLine("The user is betting against the house");
playAgain = true;
int bet = 0;
int amount=100;
while (playAgain == true)
{
Console.WriteLine("Initial balance in your account: {0} USD", amount); Console.Write("Please make your Selection (1 = Heads and 2 = Tails):\t");
user = Console.ReadLine();
//Enter Betting Amount
Console.Write("How much you wanna bet(in USD):\t");
int.TryParse(Console.ReadLine(), out bet);
//===The house is generating the random number===
house = numberGenerator.Next(1, 3);
//===The int.TryParse method converts strings into ints. It never throws an exception
while (!int.TryParse(user, out user1) || user1 <= 0 || user1 >= 3)
{
Console.Write("Please make your Selection (1 = Heads and 2 = Tails):\t");
user = Console.ReadLine();
}
//===The Logic Behind the Game====
if (user1 == 1)
{
userChoice = "Heads";
}
else
{
userChoice = "Tails";
}
if (house == 1)
{
houseChoice = "Heads";
}
else
{
houseChoice = "Tails";
}
if (house == user1)
{
amount=amount + bet;
outcome = "WIN";
}
else
{
amount = amount - bet;
outcome = "LOSE";
}
Console.Write("You chose\t");
Console.Write(userChoice);
Console.Write("\nThe House chose\t");
Console.Write(houseChoice);
Console.Write("\nYou ");
Console.Write(outcome);
Console.WriteLine("\nYour account now has: {0} USD!", amount);
//Win Lose Condition
if (amount >= 100)
{
Console.WriteLine("\nWanna try your luck once more? (Yes/No)");
again = Console.ReadLine().ToUpper();
if (again == "YES")
{
playAgain = true;
}
else if (again == "NO")
{
playAgain = false;
}
}
else
{
Console.WriteLine("Better luck next time buddy!");
playAgain = false;
Check();
}
}
Console.WriteLine("Thank you for Playing!");
Console.ReadKey();
}
//======================End Of Coin Toss================================================================
CarolynPosted Jun 16, 2013, 5:40 PM
My Roulette isn't elegant but it works. I'll be happy when we move on to web applications in this class!!!
This is what I made from the help you gave me(I have a lot of comments so I can remember and learn from the project):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static bool AllFine = true;
static string user = null;
static bool playAgain = true;
static void Main(string[] args)
{
//==The switch statement is a control statement that handles multiple selections by passing control to one of the case statements within its body
//==This is also reading the menu for the 1,2,3,4,5......
while (AllFine == true)
{
switch (DrawMenu())
{
case 1:
Console.WriteLine("Option not ready yet!");
break;
case 2:
Play();
break;
case 3:
Play2();
break;
case 4:
Play3();
break;
case 5:
Console.WriteLine("Exit");
break;
default:
break;
}
Exit();
}
Console.WriteLine("Thank you for joining us!");
Console.ReadKey();
}
//======================End of Switch Statement================================================================================
//===Coin Toss Game Starts Here===
private static void Play()
{
//===This is the user inputting their choice===
int user1;
//===This is what makes the output random===
Random numberGenerator = new Random();
string userChoice;
string houseChoice;
int house;
string outcome;
//===This makes the game easier on the eyes===
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Blue;
Console.Clear();
Console.WriteLine("The user is betting against the house");
playAgain = true;
while (playAgain == true)
{
Console.Write("Please make your Selection (1 = Heads and 2 = Tails):\t");
user = Console.ReadLine();
//===The house is generating the random number===
house = numberGenerator.Next(1, 3);
//===The int.TryParse method converts strings into ints. It never throws an exception
while (!int.TryParse(user, out user1) || user1 <= 0 || user1 >= 3)
{
Console.Write("Please make your Selection (1 = Heads and 2 = Tails):\t");
user = Console.ReadLine();
}
//===The Logic Behind the Game====
if (user1 == 1)
{
userChoice = "Heads";
}
else
{
userChoice = "Tails";
}
if (house == 1)
{
houseChoice = "Heads";
}
else
{
houseChoice = "Tails";
}
if (house == user1)
{
outcome = "WIN";
}
else
{
outcome = "LOSE";
}
Console.Write("You chose\t");
Console.Write(userChoice);
Console.Write("\nThe House chose\t");
Console.Write(houseChoice);
Console.Write("\nYou ");
Console.Write(outcome);
Check();
}
Console.WriteLine("Thank you for Playing!");
Console.ReadKey();
}
//======================End Of Coin Toss================================================================
//===Roulette Colors Game Starts Here===
private static void Play2()
{
//===This is the user inputting their choice===
int user1;
//===This is what makes the output random===
Random numberGenerator = new Random();
string userChoice;
string houseChoice;
int house;
string outcome;
//===This makes the game easier on the eyes===
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Blue;
Console.Clear();
Console.WriteLine("The user is betting against the house");
playAgain = true;
while (playAgain == true)
{
Console.Write("Please make your Selection (1 = Red and 2 = Black):\t");
user = Console.ReadLine();
//===The house is generating the random number===
house = numberGenerator.Next(1, 3);
//===The int.TryParse method converts strings into ints. It never throws an exception
while (!int.TryParse(user, out user1) || user1 <= 0 || user1 >= 3)
{
Console.Write("Please make your Selection (1 = Red and 2 = Black):\t");
user = Console.ReadLine();
}
//===The Logic Behind the Game====
if (user1 == 1)
{
userChoice = "Red";
}
else
{
userChoice = "Black";
}
if (house == 1)
{
houseChoice = "Red";
}
else
{
houseChoice = "Black";
}
if (house == user1)
{
outcome = "WIN";
}
else
{
outcome = "LOSE";
}
Console.Write("You chose\t");
Console.Write(userChoice);
Console.Write("\nThe House chose\t");
Console.Write(houseChoice);
Console.Write("\nYou ");
Console.Write(outcome);
Check();
}
Console.WriteLine("Thank you for Playing!");
Console.ReadKey();
}
//=======================================================================================================================================================================
//===Roulette Number Game Starts Here===
private static void Play3()
{
Random r = new Random();
//This is going to let the user choose a number between 1 and 37 representing the roulette wheel
int val = r.Next(1, 37);
int roulette = 0;
bool correct = false;
Console.WriteLine("Choose Your Number and Spin The Wheel .");
while (!correct)
{
Console.Write("Your Number Choice Is: ");
string input = Console.ReadLine();
if (roulette != val) //If the random number is incorrect
{
Console.WriteLine("You Lose ~ House Wins :p");
}
else
{
correct = true;
Console.WriteLine("This is your lucky day. You WIN!");
}
}
}
//=======================================END Of ROULETTE================================================================================================================================
//===Do I stay or Go Logic For The Game That I am Playing====
static void Check()
{
Console.WriteLine("\nDo you want to play again? (Yes/No)");
user = Console.ReadLine().ToUpper();
if (user == "YES")
{
playAgain = true;
}
else if (user == "NO")
{
playAgain = false;
}
else
Check();
}
//===Do I stay or Go Logic For The Game As a Whole====
static void Exit()
{
Console.WriteLine("Do you want to Exit? (Yes/No)");
string choice = Console.ReadLine().ToUpper();
if (choice == "YES")
{
AllFine = false;
}
else if (choice == "NO")
{
AllFine = true;
}
else
{
Console.WriteLine("Enter valid argument.");
Exit();
}
}
static void ErrorMessage()
{
Console.WriteLine("Typing Error, Press any key to continue.");
Console.ReadKey();
}
//=======================================================================================================================================================================
//===The Main Menu for the User====
static void DrawStarLine()
{
Console.WriteLine("****************************");
}
static void DrawTitle()
{
Console.Clear();
DrawStarLine();
Console.WriteLine("+ + + Welcome User + + +");
DrawStarLine();
}
static int DrawMenu()
{
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
int choice = 0;
DrawTitle();
DrawStarLine();
Console.WriteLine("Choose any one option:");
Console.WriteLine(" 1. Add Funds");
Console.WriteLine(" 2. Coin toss");
Console.WriteLine(" 3. Roulette Colors");
Console.WriteLine(" 4. Roulette Numbers");
Console.WriteLine(" 5. Exit program");
DrawStarLine();
Console.WriteLine("Make your choice:\t");
DrawStarLine();
//===The int.TryParse method converts strings into ints. My Choice can't be less than 1 or greater than 5
if (!int.TryParse(Console.ReadLine(), out choice) || choice < 1 || choice > 5)
{
ErrorMessage();
DrawMenu();
}
return choice;
}
}
}
CarolynPosted Jun 14, 2013, 9:19 PM
Ahhhh I see it called it when you put the Play() under Case2 I was really complicating that problem in my head that is for sure,
I truly appreciate your help I spent a good 10 hours on this before I went looking for a forum. Looks like I found the right one :)