Question: Can I have two variables in an if else statement in C#? this is what i have so far: int quantity; bool parseOkay; Console.WriteLine(tWelcome to

Can I have two variables in an if else statement in C#?

this is what i have so far:

int quantity; bool parseOkay; Console.WriteLine("\tWelcome to The Card Depot!"); // ask user if they want new or used Console.Write("Would you like to buy (N)ew or (U)sed cards: "); string option = Console.ReadLine(); if (option == "N" || option == "n") { Console.Write("How many new cards would you like to purchase: "); parseOkay = int.TryParse(Console.ReadLine(), out quantity); Console.WriteLine("Your purchase of {0} new cards comes to {1:C}", quantity, quantity * 0.85); } else { if (option == "U" || option == "u") { Console.Write("How many used cards would you like to purchase: "); parseOkay = int.TryParse(Console.ReadLine(), out quantity); Console.WriteLine("Your purchase of {0} used cards comes to {1:C}", quantity, quantity * 0.57); } else { Console.WriteLine("That menu choice is not valid."); } Console.WriteLine("Press any key to exit..."); Console.ReadKey();

I can't figure out how to print out "That input is not valid" and "That quantity is too low." when the user enters a <= 0 value and if it was a non-numerical value for the card quantity.

I know that if quantity <=0 { Console.WriteLine("That quantity is too low." } However, when i do that i get an error message that I'm trying to use an unassigned local variable

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!