Link to home
Start Free TrialLog in
Avatar of December2000
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(inputString);
            randomNumber =  + ranNumberGenerator.Next(4);    

           if (inputString == randomNumber)
               Console.WriteLine("Draw");
           else Console.WriteLine("Lose");
           Console.Read();
Avatar of BuggyCoder
BuggyCoder
Flag of India image

randomNumber is an integer and inputString a string, here is the modified version:-

string inputString;
            string r, p, c;
            int randomNumber;
            int numberString;

            Random ranNumberGenerator = new Random();
            randomNumber = ranNumberGenerator.Next(4);


            Console.Write("Enter r, p, or c");
            inputString = Console.ReadLine();
            numberString = Convert.ToInt32(inputString);
            randomNumber = +ranNumberGenerator.Next(4);

            if (numberString == randomNumber)
                Console.WriteLine("Draw");
            else Console.WriteLine("Lose");
            

Open in new window

Avatar of December2000
December2000

ASKER

Thank you!

I am getting an error on

 numberString = Convert.ToInt32(inputString);

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....
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
Avatar of BuggyCoder
BuggyCoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 :)