C# card game code problem?
i am trying to create a simple card program so that the user is presented with a number between 1 and 13 and then the computer uses a number between 1 and 13 and the user has to guess if the number the computer has is more than their number or less by typing in either higher or lower and if they guess right it will display a message telling them well done and the number which the computer had.
but my problem is is that i cannot tell the program what higher or lower means i have tried but it gives me an error stating that it cannot implicitly convert type 'bool' to 'string'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Card_Game
{
class Program
{
static void Main(string[] args)
{
int rnumber;
int hidennumber;
string userinput;
string higher;
string lower;
string end;
Random generator = new Random();
rnumber = generator.Next(1, 13);
Console.WriteLine("Your number is {0}", rnumber);
Console.WriteLine("There is now a hiden number");
hidennumber = generator.Next(1, 13);
Console.WriteLine("please enter higher or lower");
userinput = Console.ReadLine();
higher = rnumber < hidennumber;
lower = rnumber > hidennumber;
if (hidennumber > rnumber)
{
if (userinput == higher)
{
Console.WriteLine("Well Done the number was {0}", hidennumber);
}
}
Console.Read();
}
}
}
Comments
I don't quite see where the bool to string conversion is, but you do seem to have a problem with string and int types.
The user enters a string userinput. In order to compare that to the int higher you need to convert them to the same type. Since its a numeric comparison you probably want, you should convert userinput to int. The magic to do that is int.Parse(userinput) , so your line towards the end of your sample could become:
if (int.Parse(userinput) == higher)
a million. you will might desire to apply a snap shots library. opportunities are high, in case you do not understand approximately snap shots libraries you at the instant are not waiting to apply them yet, yet take a glance at them. there is DirectX (for Weendows), OpenGL (that's circulate-platform), SDL, Allegro. and a few others, yet those are the foremost ones (or those i've got heard of the main). 2. it quite is distinctive with each and every library. i in my view use DirectX. In DX9 you have a "vertex buffer" which you may desire to create for each shape, lock it, fill it quite is vertices, launch it, and run it throughout the DrawPrimitive(). you utilize the purposes of the snap shots library to entice the stuff. additionally, you heavily isn't waiting to apply a gif. you will might desire to code the factors of the explosion in, or use animating application (Blender [loose], 3DMAX [not so loose, will value you an arm], etc. etc.) and export the factors right into a format that DirectX can study (I do have faith it makes use of the .x report extension). additionally, it's going to take an prolonged time, even for a pass Fish pastime.