0% found this document useful (0 votes)
40 views2 pages

Using Namespace: "Enter Quantity:" "Enter Price:"

The document contains 3 code snippets that demonstrate calculating absolute values, total expense with discounts, and profit/loss calculations. The absolute value code takes inputs of -23.45, 234, and 12.54 and prints out their absolute values. The expense code calculates total cost, applies a 10% discount if over 5000, and prints the final amount. The profit/loss code takes in sale and cost prices, calculates profit or loss, and prints the appropriate message.

Uploaded by

Adil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

Using Namespace: "Enter Quantity:" "Enter Price:"

The document contains 3 code snippets that demonstrate calculating absolute values, total expense with discounts, and profit/loss calculations. The absolute value code takes inputs of -23.45, 234, and 12.54 and prints out their absolute values. The expense code calculates total cost, applies a 10% discount if over 5000, and prints the final amount. The profit/loss code takes in sale and cost prices, calculates profit or loss, and prints the appropriate message.

Uploaded by

Adil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

package com.java2novice.

math;

public class MyAbsEx {

public static void main(String[] args) {

double a = -23.45;

int b = 234;

double c = 12.54;

System.out.println("absolute value of a: "+Math.abs(a));

System.out.println("absolute value of b: "+Math.abs(b));

System.out.println("absolute value of c: "+Math.abs(c));

2using namespace std;

int main()
{
int totalexp, qty, price, discount;

cout<<"Enter quantity:";
cin>>qty;
cout<<"Enter price:";
cin>>price;

totalexp=qty*price;

if(totalexp>5000)
{
discount=(totalexp*0.1);
totalexp=totalexp-discount;
}

cout<<"Total Expense is Rs. "<<totalexp;

return 0;
}

include<iostream>

using namespace std;


int main ()

float s,c,pr;

cout<<"\t * Profit and Loss Calculation * "<<endl;

cout<<"\n";

cout<<"Enter the Sale Price of Product "<<endl;

cin>>s;

cout<<"Enter the Cost Price of Product "<<endl;

cin>>c;

pr=s-c;

if (s>c)

cout<<"\n";

cout<<"You have total profit of "<<pr;

else if (s<c)

cout<<"\n";

cout<<"You have total loss of "<<-pr;

else

cout<<"You have 0 Profit 0 Loss"<<endl;

You might also like