[Solved] Calculating Gain Percentage with C++

Calculating Gain Percentage: Vikram buys an old scooter for Rs. A and spends Rs. B on its repairs. If he sells the scooter for Rs. C , what is his gain %?
[Solved] Calculating Gain Percentage with C++

Write a program to compute the gain %.

Input Format:

The first input is an integer which corresponds to A. The second input is an integer which corresponds to B. The third input is a float which corresponds to gain %.

Output Format:

Refer sample input and output for formatting specifications.

The float values are displayed correct to 2 decimal places.

Sample Input and Output:

[All text in bold corresponds to input and the rest corresponds to output]


Price of old scooter:

4700

Repair amount:

800

Selling price:

5800

Gain percentage is 5.45

Solution

#include <iostream>
using namespace std;

int main()
{
    int a, b, c;
    cout<<"Price of old scooter:"<<endl;
    cin>>a;
    cout<<"Repair amount:"<<endl;
    cin>>b;
    cout<<"Selling price:"<<endl;
    cin>>c;
     printf("Gain percentage is %.2f",((c-a-b)*1.0/(a+b))*100);   
    return 0;
}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *