It looks like you're new here. If you want to get involved, click one of these buttons!
Hi, I've started out with small tutorials and know the very small basics. I know how if statements work... but this code I have here, want's me to insert the Options as many times in a row depending on which if statement.
using System;
namespace VS_Program3
{
class Program
{
static void Main(string[] args)
{
//Console Appearance
Console.Title = "Program Box";
Console.ForegroundColor = ConsoleColor.Yellow;
//Conversation Starting.
Console.WriteLine("Welcome to the movies! Buy a ticket!\nChoose Option:\nTicket for 1: A\nTickets for 2: B\nTickets for 3: C\nTickets for 4: D");
int shortingA;
int changeA;
int shortingB;
int changeB;
int shortingC;
int changeC;
int shortingD;
int changeD;
Console.ForegroundColor = ConsoleColor.Green;
if (Console.ReadLine() == "A")
{
Console.Write("That would be 5$. Please insert cash: ");
int cashA = Convert.ToInt16(Console.ReadLine());
shortingA = (5 - cashA);
changeA = cashA - 5;
if(cashA <5)
{
Console.Write("I'm sorry! Your shorting "+shortingA+"$");
}
else if(cashA >5)
{
Console.WriteLine("Thank you very much, and here's your change: "+changeA+"\nEnjoy the movie!");
}
else if(cashA == 5)
{
Console.WriteLine("Thank you very much. Enjoy the movie!");
}
}
else if (Console.ReadLine() == "B")
{
Console.Write("That would be 9$. Please insert cash: ");
int cashB = Convert.ToInt16(Console.ReadLine());
shortingB = (9 - cashB);
changeB = cashB - 9;
if(cashB <5)
{
Console.Write("I'm sorry! Your shorting "+shortingB+"$");
}
else if(cashB >5)
{
Console.WriteLine("Thank you very much, and here's your change: "+changeB+"\nEnjoy the movie!");
}
else if(cashB == 5)
{
Console.WriteLine("Thank you very much. Enjoy the movie!");
}
}
else if (Console.ReadLine() == "C")
{
Console.Write("That would be 12$. Please insert cash: ");
int cashC = Convert.ToInt16(Console.ReadLine());
shortingC = (12 - cashC);
changeC = cashC - 12;
if(cashC <5)
{
Console.Write("I'm sorry! Your shorting "+shortingC+"$");
}
else if(cashC >5)
{
Console.WriteLine("Thank you very much, and here's your change: "+changeC+"\nEnjoy the movie!");
}
else if(cashC == 5)
{
Console.WriteLine("Thank you very much. Enjoy the movie!");
}
}
else if (Console.ReadLine() == "D")
{
Console.Write("That would be 16$. Please insert cash: ");
int cashD = Convert.ToInt16(Console.ReadLine());
shortingD = (16 - cashD);
changeD = cashD - 16;
if(cashD <5)
{
Console.Write("I'm sorry! Your shorting "+shortingD+"$");
}
else if(cashD >5)
{
Console.WriteLine("Thank you very much, and here's your change: "+changeD+"\nEnjoy the movie!");
}
else if(cashD == 5)
{
Console.WriteLine("Thank you very much. Enjoy the movie!");
}
}
Console.ReadKey();
}
}
}
So just for an example to make things clear... if I had to choose C in the start, I have to insert C 3 times, because it's the third if statement. SO I do this in the console.
C
enter
C
enter
C
enter.
If I don't do the same value for all 3 attempts, it throws errors.
If I s\chose A, which is first, I'd do this:
A
enter
And it would immediately take me to the next step.
Does anyone know how I can fix this?
Answers
My bad...
I still have the problem that I have, but I fixed a few issues that for some reason doesn't make a difference to my program (everything is still working, very weird...???) but I have made it simpler. As I figure things out, I figure out how to make it easier and shorter, stronger as well as faster...
Here's the new line of code:
using System;
namespace VS_Program3
{
class Program
{
static void Main(string[] args)
{
//Console Appearance
Console.Title = "Program Box";
Console.ForegroundColor = ConsoleColor.Yellow;
//Conversation Starting.
Console.WriteLine("Welcome to the movies! Buy a ticket!\nChoose Option:\nTicket for 1: A\nTickets for 2: B\nTickets for 3: C\nTickets for 4: D");
int shorting;
int change;
Console.ForegroundColor = ConsoleColor.Green;
if (Console.ReadLine() == "A")
{
Console.Write("That would be 5$. Please insert cash: ");
int cash = Convert.ToInt16(Console.ReadLine());
shorting = (5 - cash);
change = cash - 5;
if(cash <5)
{
Console.Write("I'm sorry! Your shorting "+shorting+"$");
}
else if(cash >5)
{
Console.WriteLine("Thank you very much, and here's your change: "+change+"$\nEnjoy the movie!");
}
else if(cash == 5)
{
Console.WriteLine("Thank you very much. Enjoy the movie!");
}
}
else if (Console.ReadLine() == "B")
{
Console.Write("That would be 9$. Please insert cash: ");
int cash = Convert.ToInt16(Console.ReadLine());
shorting = (9 - cash);
change = cash - 9;
if(cash <9)
{
Console.Write("I'm sorry! Your shorting "+shorting+"$");
}
else if(cash >9)
{
Console.WriteLine("Thank you very much, and here's your change: "+change+"$\nEnjoy the movie!");
}
else if(cash == 9)
{
Console.WriteLine("Thank you very much. Enjoy the movie!");
}
}
else if (Console.ReadLine() == "C")
{
Console.Write("That would be 12$. Please insert cash: ");
int cash = Convert.ToInt16(Console.ReadLine());
shorting = (12 - cash);
change = cash - 12;
if(cash <12)
{
Console.Write("I'm sorry! Your shorting "+shorting+"$");
}
else if(cash >12)
{
Console.WriteLine("Thank you very much, and here's your change: "+change+"$\nEnjoy the movie!");
}
else if(cash == 12)
{
Console.WriteLine("Thank you very much. Enjoy the movie!");
}
}
else if (Console.ReadLine() == "D")
{
Console.Write("That would be 16$. Please insert cash: ");
int cash = Convert.ToInt16(Console.ReadLine());
shorting = (16 - cash);
change = cash - 16;
if(cash <16)
{
Console.Write("I'm sorry! Your shorting "+shorting+"$");
}
else if(cash >16)
{
Console.WriteLine("Thank you very much, and here's your change: "+change+"$\nEnjoy the movie!");
}
else if(cash == 16)
{
Console.WriteLine("Thank you very much. Enjoy the movie!");
}
}
Console.ReadKey();
}
}
}
Reminder: Still have the problem