This is question 4th of the exercise. Whatever wood variety is chosen, output price of the wood is first chosen variety is coming. Please fix the error.
using System;
namespace _5e4
{
class Furniture
{
static void Main(string[] args)
{
string choose, replay;
Console.Write("[P for pine] [O for oak] [M for mahogany] Choose varity: ");
choose = Console.ReadLine();
while (choose == "P" || choose == "O" || choose == "M")
{
if (choose == "P")
Console.WriteLine("\t\t\t\t\t\t\tPine Price $100");
if (choose == "O")
Console.WriteLine("\t\t\t\t\t\t\tOak Price = $225");
if (choose == "M")
Console.WriteLine("\t\t\t\t\t\t\tMahogany Price = $310");
replay = Choose();
}
Console.ReadKey();
}
public static string Choose()
{
Console.Write("\n[P for pine] [O for oak] [M for mahogany] Choose varity: ");
string choose = Console.ReadLine();
return choose;
}
}
}
/*
[P for pine] [O for oak] [M for mahogany] Choose varity: P
Pine Price $100
[P for pine] [O for oak] [M for mahogany] Choose varity: O
Pine Price $100
[P for pine] [O for oak] [M for mahogany] Choose varity: M
Pine Price $100
*/
Loading
VulpesPosted Aug 8, 2012, 10:45 AM
Posted Aug 8, 2012, 12:34 PM
I have fixed the error according to your advice. Now it is working correctly. Program is as follows.
using System;
namespace _5e4
{
class Furniture
{
static void Main(string[] args)
{
string choose;
Console.Write("[P for pine] [O for oak] [M for mahogany] Choose varity: ");
choose = (Console.ReadLine()).ToUpper();
while (choose == "P" || choose == "O" || choose == "M")
{
if (choose == "P")
Console.WriteLine("\t\t\t\t\t\t\tPine Price $100");
if (choose == "O")
Console.WriteLine("\t\t\t\t\t\t\tOak Price = $225");
if (choose == "M")
Console.WriteLine("\t\t\t\t\t\t\tMahogany Price = $310");
choose = Choose();
}
Console.WriteLine("Program ends");
Console.ReadKey();
}
public static string Choose()
{
Console.Write("\n[P for pine] [O for oak] [M for mahogany] Choose varity: ");
string reply = (Console.ReadLine()).ToUpper();
return reply;
}
}
}
/*
[P for pine] [O for oak] [M for mahogany] Choose varity: p
Pine Price $100
[P for pine] [O for oak] [M for mahogany] Choose varity: o
Oak Price = $225
[P for pine] [O for oak] [M for mahogany] Choose varity: m
Mahogany Price = $310
*/
VulpesPosted Aug 8, 2012, 11:16 AM
replay = Choose();
which caused the next choice to be made.
However, this choice was assigned to the 'replay' variable and 'choice' therefore had the same value as for the first choice. Consequently, it kept on printing the price of the first choice of wood even though different choices were being made.
Posted Aug 8, 2012, 10:59 AM
Please explain what is incorrect in my program.