Write a program to input name of a person and 5 grocery items he or she purchased. Calculate 10 percent discount of total purchase.
Answers
Answered by
5
Corrected Question:-
- Write a program to input name of a person and price of 5 grocery items he or she purchased. Calculate 10 percent discount of total purchase.
This is done in JAVA.
//Program to calculate 10% discount of the total purchase
package Programmer;
import java.util.Scanner;
public class Discount{
public static void main (String ar []){
Scanner sc=new Scanner (System.in);
String name="";
double price=0,total=0;
System.out.println("Enter your name");
name=sc.nextLine();
System.out.println("Enter price of 5 grocery items");
for(int I=1;I<=5;I++){
price=sc.nextDouble();
total+=price;
}
double Discount= 10/100*total;
System.out.print("Name: "+name);
System.out.print("Total purchase="+total);
System.out.print("Total purchase after discount of 10% ="+(total-Discount));
}
}
_____
Variable Description:-
- name:- to accept name of the person
- price:- to accept price of each items
- total :- to calculate the total purchase
- Discount :- to calculate the discount of 10% on total purchase
- I:- loop variable to run a loop from 1 to 5
___
• Output will be attached soon
Attachments:
Similar questions