You should have the percentage of tip based on the service that you received.
Then you multiply the percentage of tip by the amount of money that you have to pay for what you bought.
Answer:
class Main {
public static void fillTable(int [][] t, int or, int oc) {
for(int r=0; r<t.length; r++) {
for(int c=0; c<t[r].length; c++) {
t[r][c] = Math.max(1+Math.abs(r-or), 1+Math.abs(c-oc));
}
}
}
public static void dumpTable(int [][] t) {
for(int r=0; r<t.length; r++) {
for(int c=0; c<t[r].length; c++) {
System.out.printf("%3d", t[r][c]);
}
System.out.println();
}
}
public static void main(String[] args) {
int origin_row = 3;
int origin_col = 2;
int[][] table = new int[5][4]; // rows|cols
fillTable(table, origin_row, origin_col);
dumpTable(table);
}
}
Explanation:
Above program does not contain input handling and exception handling, but it does contain the cleverness of calculating the cell values. I'm hoping you can add the input handling yourself?
Answer:
import random
arr=[]
for i in range(100):
arr.append(i)
while True:
answer=random.choice(arr)
guess=int(input("enter your guess number between 0-100: "))
if answer is guess:
print("right guess\ncongratulations.....")
print("the answer was: "+str(answer))
break
elif guess < answer-20:
print("you guessed too low....\ntry again")
print("the answer was: "+str(answer))
elif guess > answer+20:
print("you guessed too high....\ntry again")
print("the answer was: "+str(answer))
else:
print("incorrect guess\ntry again")
print("the answer was: "+str(answer))
Explanation: