Computer Science, asked by Anonymous, 3 months ago

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

  1. name:- to accept name of the person
  2. price:- to accept price of each items
  3. total :- to calculate the total purchase
  4. Discount :- to calculate the discount of 10% on total purchase
  5. I:- loop variable to run a loop from 1 to 5

___

• Output will be attached soon

Attachments:
Similar questions