I was wondering if someone would be willing to assist me. The program listed below compiles, but when I run it I get the following error an exception 'System.FormatException.
I think my error is possibly convertinting the string in the readLine to a boolean inorder to test the true false in my if statements.

using System;

public class HotDogSales

	public static void Main()
		const double basicDogPrice = 2.00;
		const double chiliPrice = 0.69;
		const double cheesePrice = 0.49;
		string wantChiliBool, wantCheeseBool;
		bool  wantChili, wantCheese;
		double price;
		bool Y = true, y = true;
		Console.Write("Do you want chili on your dog?" );
		wantChiliBool = Console.ReadLine();
		wantChili = Convert.ToBoolean(wantChiliBool);
		Console.Write("Do you want cheese on your dog?" );
		wantCheeseBool = Console.ReadLine();
		wantCheese = Convert.ToBoolean(wantCheeseBool);
		if(wantChili = Y || y && wantCheese == Y || y)
			price = basicDogPrice + chiliPrice + cheesePrice;
		else if(wantChili = Y || y)
			price = basicDogPrice + chiliPrice;
		else if (wantCheese = Y || y)
			price = basicDogPrice + cheesePrice;

			price = basicDogPrice;
		Console.WriteLine("Your total is {0}", price.ToString("C"));


Recommended Answers

All 3 Replies

You should answer with "true" or "false" to avoid exception raising...

You should answer with "true" or "false" to avoid exception raising...

use == instead of =

Thanks, I actually used a a GetChar() and changed my response varibles to char, like they should have been.

Thank you for input though.

You should answer with "true" or "false" to avoid exception raising...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.