Wednesday 9 January 2013

Let Us C chapter 2 problem No: C-a



//Program to calculate profit and lost

#include<iostream>
#include<windows.h>

using namespace std;

class shop
{
    int sp,cp,p;
public:
    void in()
    {
        cout<<"Enter the cost price:     ";
        cin>>cp;
        cout<<"Enter the selling price:  ";
        cin>>sp;
    }

    void calc()
    {
        p=sp-cp;
        if(p>=0)
        {
         cout<<"You made a profit of "<<p<<"$";
        }
        else
        {
            cout<<"You lost "<<p*(-1)<<"$ in this business";
        }
    }
};

int main(void)
{
    shop s;
    s.in();
    s.calc();
    cout<<endl;
}


No comments:

Post a Comment

Comments please: