DEV Community

Oluwatoyin Ariyo
Oluwatoyin Ariyo

Posted on

100 Days of Code Challenge: Day 2

It is Day 2 of me doing the 100 Days of Code challenge from Angela Yu's 100 Days of Code: The Complete Python Pro Bootcamp where I learnt about mathematical operations and data type manipulation like string formatters.

Compared to day 1, it was definitely a bit more difficult as it involved a lot of mathematics and I am not good at doing that without a calculator. Using Python Tutor definitely helped me build and understand the project more as it allowed me to break down the program line by line so I can see how each variable was calculated.

Screenshot of code shown line by line in Python Tutor

For the C# equivalent, it was a lot harder to program than Day 1 because Python and C# are so different. The C# program manages to run but it does not seem to show the correct result: for the above input, it would say the final amount is 14.00 instead of 15.40.

Image description

using System;

class Program {
  public static void Main (string[] args) {
    Console.WriteLine ("Here is Toyin's tip calculator!");
    Console.WriteLine("What was the total bill?");
    decimal bill = decimal.Parse(Console.ReadLine());
    Console.WriteLine("Was the tip 10, 12 or 15?");
    int tip = int.Parse(Console.ReadLine());
    Console.WriteLine("How many people are splitting the bill?");
    int people_split = int.Parse(Console.ReadLine());
    int tip_percentage = tip / 100;
    decimal total_tip = bill * tip_percentage;
    decimal total_bill = bill + total_tip;
    decimal bill_per_person = total_bill / people_split;
    decimal final_amount = Math.Round(bill_per_person, 2);
    Console.WriteLine("Each person should pay: " + "$" + final_amount.ToString("0.00")); //Prints out wrong answer: 14 instead of 15.4 for total bill of 70, tip of 10 and 5 people splitting bill
    }
}
Enter fullscreen mode Exit fullscreen mode

I'm not sure where the issue was in converting the Python code and why it is displaying a different result. Enjoyment wise, I am definitely liking how simple the syntax is with Python, I really wish I started using this programming language a lot earlier.

I plan on posting about Day 3 of the Code Challenge tomorrow.

Top comments (0)