I'm fairly new to programming and I decided to make a small C# console program for practice. The program asks for user input and gives a random "compliment", it also has a small chance to give a bonus "compliment". How can I improve my code and also what whould you recomend me to try adding? -ps. the "compliments" are mostly a joke.
My code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Compliment_giver
{
class Program
{
static void Main(string[] args)
{
Greeting();
start:
string answer = Console.ReadLine();
if(answer != "yes" && answer != "no")
{
Console.WriteLine("Unexpected input, please type either \"yes\" or \"no\"");
goto start;
}
while(answer == "yes")
{
Console.Clear();
string result = RandomCompliment();
Console.WriteLine("\n{0}\n",result);
if (BonusCompliment())
Console.WriteLine("BONUS COMPLIMENT!\nYou are Very Lucky\n");
Console.Write("Would you like another compliment? : ");
goto start;
}
}
public static string RandomCompliment()
{
string[] compliment = new string[10];
compliment[0] = "Your hair smells nice";
compliment[1] = "Your face is ok I guess";
compliment[2] = "You're probably smarter than a penguin";
compliment[3] = "Your body appears to be human";
compliment[4] = "You seem pleasant";
compliment[5] = "You likely aren't the most annoying person in the world";
compliment[6] = "You are talanted... at something possibly";
compliment[7] = "Your eyes are of good color";
compliment[8] = "Your are the best looking person in a room by yourself";
compliment[9] = "You are right all the time, exept only when you are not";
Random number = new Random();
int rng = number.Next(0, 10);
string _result = compliment[rng];
return _result;
}
public static void Greeting()
{
Console.WriteLine("Welcome to the Compliment Giver 3000!");
Console.WriteLine("This program is designed to give free compliments to make you feel better");
Console.Write("Do you want a compliment? yes/no: ");
}
public static bool BonusCompliment()
{
Random percentage = new Random();
int bonus = percentage.Next(1, 101);
if (bonus <= 3)
return true;
else
return false;
}
}
}
talanted
->talented
,Your are
->You are
orYou're
. \$\endgroup\$goto
in multiple places. More studying is indeed a good idea. \$\endgroup\$