Hi.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Uppgift_1
{
class Product
{
private string Produuct;
private decimal Price;
private decimal Vat;
private bool Food;
private int Count;
private const decimal foodVATRate = 0.12m, otherVATRate = 0.25m;
private decimal Finalprice;
private decimal Rate;
public void Readinput()
{
Console.Write("\n\nWhat is the product you want: ");
Produuct = Console.ReadLine();
Console.Write("Unit price: ");
decimal.TryParse(Console.ReadLine(), out Price);
Console.Write("Food item y/n: ");
char answer = char.Parse(Console.ReadLine());
if ((answer == 'y') || (answer == 'Y'))
Food = true;
else
Food = false;
Console.Write("Count: ");
int.TryParse(Console.ReadLine(), out Count);
Finalprice = (decimal)(Price * Count);
}
private void cal()
{
char answer = char.Parse(Console.ReadLine());
if ((answer == 'y') || (answer == 'Y'))
Vat = foodVATRate;
else
Vat = otherVATRate;
Rate = Finalprice * Vat;
}
public void PrintRecept()
{
Console.Write("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++");
Console.Write("\n\nThe product you want is: " + Produuct);
Console.Write("\nThe price: "+ Price);
Console.Write("\nFood item: "+Food);
Console.Write("\nCount: "+Count);
Console.Write("\n\nTotal price: "+Finalprice);
Console.Write("\nVAT at: " +Rate);
Console.Write("\n\n++++++++++++++++++++++++++++++++++++++++++++++++++++++");
}
}
}
Can any way tell my way i don't get any thing in Console.Write("\nVAT at: " +Rate);?
Loading
johan sPosted Jan 18, 2012, 7:08 AM
VulpesPosted Jan 18, 2012, 6:58 AM
johan sPosted Jan 18, 2012, 6:50 AM
I mean when i come to the line to show if it is a food or noot. When i press Y it will show the foodVATRate. so when i come to the final price it will take the
finalprice and * it white the food question like if i press y is going to be finalprice*foodVATRate and it will be the VAT
VulpesPosted Jan 18, 2012, 6:40 AM
johan sPosted Jan 18, 2012, 6:27 AM
and the Console.Write("\nVAT at " + (Vat * 100m) + "% : " + Rate); dident help me in my.
and i can get the cal(); in to my.
static void Main(string[] args)
{
Console.Title = "Tax Calculator";
Product obj = new Product();
obj.Readinput();
obj.PrintRecept();
Console.WriteLine("\n\n\nPress enter to exit");
Console.ReadLine();
for i get a Error Product.cal()' is inaccessible due to its protection level
Karthik AgarwalPosted Jan 18, 2012, 5:44 AM
There should be someone who should call Readinput(), cal() and PrintRecept() functions right. That is what you missed. Add those then your code should work fine i hope
VulpesPosted Jan 18, 2012, 5:41 AM
The line which you say doesn't show anything does in fact show the VAT on the transaction.
If you want to show the VAT rate as well, then change that line to:
Console.Write("\nVAT at " + (Vat * 100m) + "% : " + Rate);
Karthik AgarwalPosted Jan 18, 2012, 5:33 AM