I haven't used C# in many years an need basically a 1 liner. I have created a bus ticket booking form of which I have a combobox for destinations and radio button for Class Types. The Middle class price from JHB to PTA is R85.50, Economy price is 30% off the middle class and Luxury 50% extra from the Middle Class.
So when the Total button is clicked then
private void btnTotal_Click(object sender, EventArgs e)
{
if ((CboxDestination.Text == "JHB To PTA")&&(rdbEconomy.Checked))
{
lblTotal = ???;
Ive tried my calculations but i get different errors, 1 being that i'm trying to use a double on a string. I had already tried declaring JHbToPTA as a double.
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Railway_Booking
{
public partial class Form1 : Form
{
Double JHBToPTA = 85.50;
Please anyone help fill in the correct calculation, i'm really bad in percentages but the answer should = to 59.85
Seems like my issue was not really about the Math. I worked it out like so:`
public partial class Form1 : Form
{
decimal ToPTA = 85.50m;
decimal discount = (0.7m/ 100) *100;
` so added an m to my decimals
And then my label display converted to string
lblTotal.Text = Convert.ToString(ToPTA * discount);
Thanks again
it's okay, I'm also weak in maths, but there's a simple formula for percentage.
if you want to get a percentage, the formula is: (marks you got / total marks) * 100
if you have Got percentage, but don't know how much marks you have got(but you do know the total marks) then the formula will be: My Marks = (Total marks * percentage marks) / 100
in your case, I can see that you have declared JHBToPTA as a "double" type, but since it's currency, you should have chosen the "decimal" type. it'll be more convenient.
since the economy price is 30% of the middle class, then to get the price the formula will be,
(30 * 85.50) / 100 = 25.65
so, if you give a discount of 30 percent, then you just have to subtract 25.65 from the middle-class price ie 85.50 - 25.65 = 59.85
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Railway_Booking
{
public partial class Form1 : Form
{
decimal JHBToPTA = 85.50;
decimal discount = (30 * JHBToPTA) / 100
decimal final_price = JHBToPTA - discount //i.e. 59.85
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.