Tip Calculator

Collapse Content

You are working on an app to calculate tips. Given 2 ints: a, for the purchase amount in cents, and b, for the quality of service received, can you calculate the tip in cents? Round the answer down to the nearest cent. Calculate the tip according to the following table:

Quality Percent decimal
1 5% 0.05
2 10% 0.1
3 15% 0.15
4 20% 0.2
5 25% 0.25

Example Input/Output
Given an input of 1000 3, return 150.

There was a rating of 3 which according to the above table means you should give a tip of 15%.

1000 * 0.15 = 150.

Java Casting Types

Click for More


Calculate the tip as above and return an int of the tip in cents (rounded down).

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.


  • Completed, but won't check off.

  • Ha, I was just using this formula working only with int values:
    x = (1000*15)/100

  • Just gotta say that thanks for including quotes, it keeps me somewhat interested and inspired at the same time while going through this awesome noob training. Pura vida!

  • int[] ar = {0,5,10,15,20,25};
        return (a * ar[b])/100;
  • ahahaha :D i don't understand the instructions????
    hmpff guess so ... i couldn't figure out why those are the outputs ... -.-
    can someone explain the instructions ? hehehe :)

  • ahhhh okey got it myself ehehe :D anyways thanks :)

  • double f= b*.05; // .05, .1, .15, .2, .25
    double c= a*f;
    return (int)c;

  • If you just use doubles instead of integers then integers become doubles.
    example 5/2=2 but 5/2.0=2.5

    my code

  • I don't understand the proplem!!!

  • I don't understand the problem.

  • You just need to calculate the tip according to the given table. The tip should be a percentage of the the total purchase. I added an example to make it clearer.

  • easy peoples
    import java.util.Scanner;

    public class Main {

    static int doStuff(int a, int b){
            case 1:
                return (int)(a*0.05);
  • def do_stuff(a, b):



    output += thisdict.get(b)

    return x
    my answer using python

  • #include

    using namespace std;

    int func(int a , int b){

    return a*(b*0.05);

    int main()

    int a,b;
    cin>>a; // no of purchase amount:
    cin>>b; // the quality of service recieved:


Contact Us
Sign in or email us at [email protected]