December2000
asked on
C# Calling Random Variables
Need a extra pair of eyes... What am I doing wrong with comparing random numbers and the input string
using System;
using System.Collections.Generic ;
using System.Linq;
using System.Text;
namespace test
{
public class Program
{
static void Main(string[] args)
{
string inputString;
string r, p, c;
int randomNumber;
string numberString;
Random ranNumberGenerator = new Random();
randomNumber = ranNumberGenerator.Next(4) ;
Console.Write("Enter r, p, or c");
inputString = Console.ReadLine();
numberString = Convert.ToInt32(inputStrin g);
randomNumber = + ranNumberGenerator.Next(4) ;
if (inputString == randomNumber)
Console.WriteLine("Draw");
else Console.WriteLine("Lose");
Console.Read();
using System;
using System.Collections.Generic
using System.Linq;
using System.Text;
namespace test
{
public class Program
{
static void Main(string[] args)
{
string inputString;
string r, p, c;
int randomNumber;
string numberString;
Random ranNumberGenerator = new Random();
randomNumber = ranNumberGenerator.Next(4)
Console.Write("Enter r, p, or c");
inputString = Console.ReadLine();
numberString = Convert.ToInt32(inputStrin
randomNumber = + ranNumberGenerator.Next(4)
if (inputString == randomNumber)
Console.WriteLine("Draw");
else Console.WriteLine("Lose");
Console.Read();
ASKER
Thank you!
I am getting an error on
numberString = Convert.ToInt32(inputStrin g);
say's "Input string was not in a correct format."
I am getting an error on
numberString = Convert.ToInt32(inputStrin
say's "Input string was not in a correct format."
you must be entering a string in console...
use int.tryparse to check if integer is added or not....
use int.tryparse to check if integer is added or not....
ASKER
Thanks, as obvious I am a newbie, When I use number it works, How do I use the int.tryparse? How would I compare r to random generated r, p, s ? I am having a datatype issue
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome still not there but, I am a lot further than I was... sorta stuck because the only characters that the computer should be able to choose from is r, p, s (it is a rock paper scissor game) ... However, you have more than earned the points already... thank you :)
Open in new window