# Tip Calculator

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`.

Explanation
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

### Challenge

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

Alternatively, you can try out Learneroo before signing up.

• #### Matt

Completed, but won't check off.

• #### Кирилл Варивода

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

• #### David

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!

• #### isnard

``````int[] ar = {0,5,10,15,20,25};
return (a * ar[b])/100;
``````
• #### Shena

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 :)

• #### Shena

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

• #### Bernard Mitchell

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

• #### thales

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

my code

• #### Islam Elzohary

I don't understand the proplem!!!

• #### Karina Nihalani

I don't understand the problem.

• #### Learneroo

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.

• #### Anand Ani

easy peoples
import java.util.Scanner;

public class Main {

``````static int doStuff(int a, int b){

switch(b)
{
case 1:
return (int)(a*0.05);
``````
• #### Hanlise

def do_stuff(a, b):
output=int()

thisdict={
1:0.05,
2:0.1,
3:0.15,
4:0.2,
5:0.25

}

output += thisdict.get(b)

x=a*output
return x

• #### Dheeraj Parmar

#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:
cout<<func(a,b);

}

• #### AMR

Using Python - Do you guys think this code is too long and messy?

price_of_meal = float(input("How much did your meal cost: "))
quality_of_service = int(input("Rate the quality of service based from 1 to 5: "))

• #### Roger

const service = {
1: 0.05,
2: 0.1,
3: 0.15,
4: 0.2,
5: 0.25,
}

function qualityOfService(a, b) {
let tip = a * service[b]
return tip
};

• #### Roger

const service = {
1: 0.05,
2: 0.1,
3: 0.15,
4: 0.2,
5: 0.25,
}

function qualityOfService(a, b) {
let tip = a * service[b]
return tip += a
}
console.log(qualityOfService(10, 3).toFixed(2))