New Posts  All Forums:Forum Nav:

Random Responses in c#

post #1 of 5
Thread Starter 
this is continued from the other thread I made last week.
basically, I've got the program working, I just need to know how to add random responses, e.g.


Quote:
Responses to a correct answer:
Very Good!
Excellent!
Nice Work!
Keep up the good work!.
Quote:
Responses to an incorrect answer:
No. Please try again.
Wrong. Try once more.
Don’t give up!
No Keep trying.
how do I change from this code :if (input == answer)
{
Console.WriteLine("\
Very good!"); //Right Answer
Console.ReadLine();

}
else
{
Console.WriteLine("\
No. Please try again.");
Console.ReadLine(); //WRONG ANSWER
}


to output the random responses? any help would be appreciated
Ivy-E Defined
(17 items)
 
  
CPUMotherboardGraphicsRAM
4930K @ 4.5ghz w/ 1.336v RAMPAGE IV FORMULA GTX 980 Jetstream  G.Skill Ripjaws 16GB 1600mhz 
Hard DriveCoolingOSMonitor
120GB Samsung 840 EVO + 6TB (Storage) Corsair H80i w/ 2 x SP120 Windows 7 Ultimate 64-Bit Asus VG278HE  
KeyboardPowerCaseMouse
Ducky Shine 3 - Brown Cherry MX Switch - Green LED Corsair AX860  Fractal Design Define R4 Black Pearl w/ Window  Razer DeathAdder 2013 
Mouse PadAudioAudioAudio
Overclockers Medium Mouse Mat KRK ROKITS Fiio E10K  Audio Technica ATH-M50 
  hide details  
Reply
Ivy-E Defined
(17 items)
 
  
CPUMotherboardGraphicsRAM
4930K @ 4.5ghz w/ 1.336v RAMPAGE IV FORMULA GTX 980 Jetstream  G.Skill Ripjaws 16GB 1600mhz 
Hard DriveCoolingOSMonitor
120GB Samsung 840 EVO + 6TB (Storage) Corsair H80i w/ 2 x SP120 Windows 7 Ultimate 64-Bit Asus VG278HE  
KeyboardPowerCaseMouse
Ducky Shine 3 - Brown Cherry MX Switch - Green LED Corsair AX860  Fractal Design Define R4 Black Pearl w/ Window  Razer DeathAdder 2013 
Mouse PadAudioAudioAudio
Overclockers Medium Mouse Mat KRK ROKITS Fiio E10K  Audio Technica ATH-M50 
  hide details  
Reply
post #2 of 5
The first thought that comes to my mind is List<string>.
TheHydra
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 @ 3.6 EVGA P55 FTW Sapphire TOXIC 2GB 6950 CORSAIR XMS3 4 x 2GB CMX4GX3M2A1600C7 
Hard DriveOSKeyboardPower
C300 64Gb + 2x F3 HD103SJ 1TB in RAID 0 Win7 x64 Razer BlackWidow Corsair 750HX 
CaseMouseMouse Pad
Lian Li A05NB with 140mm top fan. Razer DeathAdder Razer Kabuto 
  hide details  
Reply
TheHydra
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 @ 3.6 EVGA P55 FTW Sapphire TOXIC 2GB 6950 CORSAIR XMS3 4 x 2GB CMX4GX3M2A1600C7 
Hard DriveOSKeyboardPower
C300 64Gb + 2x F3 HD103SJ 1TB in RAID 0 Win7 x64 Razer BlackWidow Corsair 750HX 
CaseMouseMouse Pad
Lian Li A05NB with 140mm top fan. Razer DeathAdder Razer Kabuto 
  hide details  
Reply
post #3 of 5
Thread Starter 
how do I use that? haven't got that far in c# yet
Ivy-E Defined
(17 items)
 
  
CPUMotherboardGraphicsRAM
4930K @ 4.5ghz w/ 1.336v RAMPAGE IV FORMULA GTX 980 Jetstream  G.Skill Ripjaws 16GB 1600mhz 
Hard DriveCoolingOSMonitor
120GB Samsung 840 EVO + 6TB (Storage) Corsair H80i w/ 2 x SP120 Windows 7 Ultimate 64-Bit Asus VG278HE  
KeyboardPowerCaseMouse
Ducky Shine 3 - Brown Cherry MX Switch - Green LED Corsair AX860  Fractal Design Define R4 Black Pearl w/ Window  Razer DeathAdder 2013 
Mouse PadAudioAudioAudio
Overclockers Medium Mouse Mat KRK ROKITS Fiio E10K  Audio Technica ATH-M50 
  hide details  
Reply
Ivy-E Defined
(17 items)
 
  
CPUMotherboardGraphicsRAM
4930K @ 4.5ghz w/ 1.336v RAMPAGE IV FORMULA GTX 980 Jetstream  G.Skill Ripjaws 16GB 1600mhz 
Hard DriveCoolingOSMonitor
120GB Samsung 840 EVO + 6TB (Storage) Corsair H80i w/ 2 x SP120 Windows 7 Ultimate 64-Bit Asus VG278HE  
KeyboardPowerCaseMouse
Ducky Shine 3 - Brown Cherry MX Switch - Green LED Corsair AX860  Fractal Design Define R4 Black Pearl w/ Window  Razer DeathAdder 2013 
Mouse PadAudioAudioAudio
Overclockers Medium Mouse Mat KRK ROKITS Fiio E10K  Audio Technica ATH-M50 
  hide details  
Reply
post #4 of 5
What i would do is initialize a string array and input each correct response string into it.

string[] correctResponses = new string[4]

correctResponses[0] = "Very Good"
correctResponses[1] = "Excellent"
..
...

Random generator = new Random();
int myRandom;

This would initialize the random generator so you can get a random integer to correspond to your array.


if (input == answer)
{
myRandom = generator.Next(4); //Will give you a random number between 0-3 for 4 total numbers

Console.WriteLine(correctResponses[myRandom]);

}


Forgive me if there is a better or faster way to do this just pulled this off the top of my head.
Edited by mykah89 - 1/3/11 at 10:20am
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
I5 760 GA-H55N GTX 470 PNY Optima 8GB 
Hard DriveMonitorPowerCase
Spinpoint F4 LG227WTG sg07 PSU Sugo sg07 
Mouse
CM Sentinel 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
I5 760 GA-H55N GTX 470 PNY Optima 8GB 
Hard DriveMonitorPowerCase
Spinpoint F4 LG227WTG sg07 PSU Sugo sg07 
Mouse
CM Sentinel 
  hide details  
Reply
post #5 of 5
Thread Starter 
Quote:
Originally Posted by mykah89 View Post
What i would do is initialize a string array and input each correct response string into it.

string[] correctResponses = new string[4]

correctResponses[0] = "Very Good"
correctResponses[1] = "Excellent"
..
...

Random generator = new Random();
int myRandom;

This would initialize the random generator so you can get a random integer to correspond to your array.


if (input == answer)
{
myRandom = generator.Next(4); //Will give you a random number between 0-3 for 4 total numbers

Console.WriteLine(correctResponses[myRandom]);

}


Forgive me if there is a better or faster way to do this just pulled this off the top of my head.

thanks! this is exactly what I needed! +Rep to you!
Ivy-E Defined
(17 items)
 
  
CPUMotherboardGraphicsRAM
4930K @ 4.5ghz w/ 1.336v RAMPAGE IV FORMULA GTX 980 Jetstream  G.Skill Ripjaws 16GB 1600mhz 
Hard DriveCoolingOSMonitor
120GB Samsung 840 EVO + 6TB (Storage) Corsair H80i w/ 2 x SP120 Windows 7 Ultimate 64-Bit Asus VG278HE  
KeyboardPowerCaseMouse
Ducky Shine 3 - Brown Cherry MX Switch - Green LED Corsair AX860  Fractal Design Define R4 Black Pearl w/ Window  Razer DeathAdder 2013 
Mouse PadAudioAudioAudio
Overclockers Medium Mouse Mat KRK ROKITS Fiio E10K  Audio Technica ATH-M50 
  hide details  
Reply
Ivy-E Defined
(17 items)
 
  
CPUMotherboardGraphicsRAM
4930K @ 4.5ghz w/ 1.336v RAMPAGE IV FORMULA GTX 980 Jetstream  G.Skill Ripjaws 16GB 1600mhz 
Hard DriveCoolingOSMonitor
120GB Samsung 840 EVO + 6TB (Storage) Corsair H80i w/ 2 x SP120 Windows 7 Ultimate 64-Bit Asus VG278HE  
KeyboardPowerCaseMouse
Ducky Shine 3 - Brown Cherry MX Switch - Green LED Corsair AX860  Fractal Design Define R4 Black Pearl w/ Window  Razer DeathAdder 2013 
Mouse PadAudioAudioAudio
Overclockers Medium Mouse Mat KRK ROKITS Fiio E10K  Audio Technica ATH-M50 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming