ok so i am new to c# and i am trying to write a program that asked the user for input on what item they want to buy, the price for the item and to show the input of the price after sales tax.i am having trouble getting the price with the sales tax to show. help please

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lab
{
    class Program
    {
        static void Main(string[] args)
        {
            string product;
            float price;
            float salesTax = 8.25F;
            float shipping;

            Console.WriteLine("Welcom to &Inc");
            Console.WriteLine("What is the product you want?");
            product = Console.ReadLine();
            Console.WriteLine("What is the price");
            price = Single.Parse(Console.ReadLine());
            Console.WriteLine(price);
            Console.WriteLine("How much is product with sales tax");
            price = price * salesTax + price;
            Console.WriteLine("This is the price with sales tax");
            Console.WriteLine(price);
        }
    }
}

Sales tax is a percentage, so you should divide it by 100 somewhere. May as well handle that in the declaration

float salesTax = 8.25F/100; // or simply hardcode 0.0825f

This won't affect your output, but you can also simplify the code on the modified price calculation. A couple of different ways, actually.

//price += price * salesTax; // 1st option
            price *= (1 + salesTax); // 2nd option

o ok. thank you that really did help alot!

Good. Beyond that, if you're running it from a debug build and not from a command line and you need it to stick on the screen after the program has spit out the output, you can simply throw in a Console.Read() after the last Console.WriteLine(...) statement. The program will then close once you hit Enter (or continue on to do something else, if code were to follow the .Read() statement).

Be a part of the DaniWeb community

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