Newport Posted February 19, 2008 Posted February 19, 2008 using System;using System.Collections.Generic; using System.Text; namespace Proj2Prep2 { class Program { static double itemName = 0, // entered at keyboard cameraPrice = 0, // entered at keyboard cameraDiscount = 0, // cameraPrice * cameraDiscount cameraAfterDiscount = 0, // camera price after discount cameraFinalPrice = 0; // cameraTax + cameraAfterDiscount const double cameraTax = .06; // 6 percent camera tax static void Main(string[] args) { // Ask the user for input Console.Write("Enter the Item Name: "); // Convert the input to double and store it in the itemName variable itemName = Convert.ToDouble(Console.ReadLine()); // Ask the user to input their pay per hour Console.Write("Enter the Price ex.(99.99): "); // Convert the input to double and store it in the cameraPrice variable cameraPrice = Convert.ToDouble(Console.ReadLine()); // calculate the values for grossPay, amtWithheld and netPay calculations(); // Echo the input and display the calculated values Console.WriteLine("Item:\t\t\t{0}", itemName); Console.WriteLine("Original Price:\t\t{0:C}", cameraPrice); Console.WriteLine("Discount:\t\t{0:C}", cameraDiscount); Console.WriteLine("Price after Discount:\t{0}", cameraDiscount); Console.WriteLine("Tax:\t{0:c}", cameraTax); Console.WriteLine("Final Price\t\t\t{0:C}", cameraFinalPrice); Console.ReadLine(); }//end of Main static void calculations() { cameraDiscount = cameraPrice * .15; cameraTax = cameraAfterDiscount * .06; cameraFinalPrice = cameraTax + cameraAfterDiscount; }// end of Main static void myOutput() { Console.WriteLine("Item:\t\t\t{0}", itemName); Console.WriteLine("Original Price:\t\t{0:C}", cameraPrice); Console.WriteLine("Discount:\t\t{0:C}", cameraDiscount); Console.WriteLine("Price after Discount:\t{0}", cameraDiscount); Console.WriteLine("Tax:\t{0:c}", cameraTax); Console.WriteLine("Final Price\t\t\t{0:C}", cameraFinalPrice); Console.ReadLine(); } } } The part that I bolded and underlined keeps poping up as my only error: Error 1 The left-hand side of an assignment must be a variable, property or indexer What does this mean? I am completely baffled by this error. It is a variable as stated in my input.... Any ideas? Share this post Link to post Share on other sites More sharing options...
Nemo Posted February 19, 2008 Posted February 19, 2008 cameraAfterDiscount - where do you assign a value to this variable? You calculate cameraDiscount but not the after discount value. Also, in this line Console.WriteLine("Price after Discount:\t{0}", cameraDiscount); you're using cameraDiscount, it should be cameraAfterDiscount. Share this post Link to post Share on other sites More sharing options...
Nemo Posted February 19, 2008 Posted February 19, 2008 You defined cameraTax as a constant then tried to assign a calculated value to it. const double cameraTax = .06; // 6 percent camera tax . . . . cameraTax = cameraAfterDiscount * .06; That's the source of the error. Share this post Link to post Share on other sites More sharing options...
Newport Posted February 19, 2008 Posted February 19, 2008 You defined cameraTax as a constant then tried to assign a calculated value to it. const double cameraTax = .06; // 6 percent camera tax . . . . cameraTax = cameraAfterDiscount * .06; That's the source of the error. I worked through everything and even went to my dad's work. Hes in charge of all of the phones, internet, satellite, everything electronic for the Government of Kansas City, Kansas. He called up 4 of his IT minions and they helped me out. It was awesome. Anyway, here's what the finished program looks like. :thumbs-up: using System;using System.Collections.Generic; using System.Text; namespace cameraPrice { class Program { static string itemName = ""; static double cameraPrice = 0, // entered at keyboard cameraAfterDiscount = 0, // camera price after discount cameraFinalPrice = 0, // cameraTax + cameraAfterDiscount cameraTax = 0, // camera tax is 6 percent cameraDiscount = 0; //camera discount is 15 percent // end of static varible list static void Main(string[] args) { Console.WriteLine("\tProject 2 by Liberty Ruddy Sec 006\n"); // Ask the user for input Console.Write("Enter the Item Name: "); itemName = Console.ReadLine(); // store item name in itemName variable // Ask the user to input the price for the item Console.Write("\nEnter the Price ex.(99.99): "); // Convert the input to double and store it in the cameraPrice variable cameraPrice = Convert.ToDouble(Console.ReadLine()); // Call the calculations and myOutput here calculations(); myOutput(); }//end of Main static void calculations() { cameraDiscount = cameraPrice * .15; cameraAfterDiscount = cameraPrice - cameraDiscount; cameraTax = cameraAfterDiscount * .06; cameraFinalPrice = cameraTax + cameraAfterDiscount; }// end of Main static void myOutput() { Console.WriteLine("\nItem:\t\t\t{0}", itemName); Console.WriteLine("Original Price:\t\t{0:C}", cameraPrice); Console.WriteLine("Discount:\t\t{0:C}", cameraDiscount); Console.WriteLine("Price after Discount:\t{0:C}", cameraAfterDiscount); Console.WriteLine("Tax:\t\t\t{0:c}", cameraTax); Console.WriteLine("Final Price\t\t{0:C}", cameraFinalPrice); Console.ReadLine(); } } } Thanks for your replies though. :-) The 2 bolded statements were where I was having trouble. At first, i placed "itemName" with all of the variables and assigned it as a double even though the input for that variable would never be a number. So i created its own string. I also screwed up the part where the item cost was to be converted to double. That was fixed and besides a few missing tabs and line spaces, the program worked fine. Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now