Here is a very simple program which is actually not working properly in Dev c++;
When i compile the program it shows 0 errors,yet it doesn't run completely.
Whreas if i run the same one in Borlan c++ it runs to completion,no problem.
What to do such that it works properly n Dev c++.

#include<iostream.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
class Deparmental
{
char Prod_name[50],Dis_type;
int long  Listprice,Distprice;  int Net;
void Cal_price()
{
int percent;
  if (strcmp(Prod_name,"Washing Machine")==0)
  Listprice=12000;
  if (strcmp("Colour Television",Prod_name)==0)
  Listprice=17000;
  if (strcmp(Prod_name,"Refrigerator")==0)
  Listprice=18000;
  if (strcmp(Prod_name,"OTG")==0)
  Listprice=8000;
  if (strcmp(Prod_name,"CD Player")==0)
  Listprice=4500;
if(Dis_type=='F')
percent=17;
if(Dis_type=='N')
percent=10;
Distprice=(Listprice*percent)/100;
Net=Listprice-Distprice;
}

public:
int  Accept()
{
cout<<"\n WELCOME TO CUSTOMER BILL GENERATION PROGRAM";
cout<<"\n Enter product name ";
gets(Prod_name);
cout<<"\n Enter product  discount type ";
cin>>Dis_type;
Cal_price();
return 0;
}
int ShowBill()
{
cout<<"\n BILL ";
cout<<"\n Product purchased "<<Prod_name;
cout<<"\n Net price "<<Listprice;
cout<<"\n Dicount price "<<Distprice;
cout<<"\n Net price after deduction "<<Net;
return 0;
}
};
int main()
{

Deparmental A;
A.Accept();
A.ShowBill();
return 0;


}

When you say "it doesn't run to completion", where exactly does the program stop working? Which version of Dev-C++ are you using?

Before I get into your actual code, I have a few comments and suggestions to make. First off, get rid of Dev-C++ and get Code::Blocks. Dev-C++ hasn't been updated in eight years, and the version of MinGW/GCC that comes with it is equally dated. You could update the version of GCC, I suppose, but Dev-C++ still would have the compiler options and settings from 2005; it is easier and better just to get an up-to-date IDE. Besides, Code::Blocks fixes several of the flaws in Dev-C++, such as closing the program console immediately after the program exits; in Code::Blocks, the console stays open until you hit a key or close it manually, which is a definite plus.

Second, use the modern forms of the standard C++ headers. Since 1998, the standard has called for the '.h' extension to be dropped from the stnadard header names, and for the C style library headers to be prepended with a 'c'. For example, <iostream.h> is now just <iostream>, while <stdio.h> and <stdlib.h> are now <cstdio> and <cstdlib>. This has been in general use since around 2002; there is no excuse to still be using the older header names in 2013.

Third, you need to be more careful about indentation. Your indentation and bracing are all over the place, making teh code nearly impossible to read. There is no reason for this: both Dev-C++ and Code::Blocks come with a plug-in that auto-indents your code for you. Please show some consideration for people who may need to read and fix your code (including yourself in the future).

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>

class Departmental
{
private:
    char Prod_name[50],Dis_type;
    int long  Listprice,Distprice;
    int Net;

    void Cal_price()
    {
        int percent;
        if (strcmp(Prod_name,"Washing Machine")==0)
            Listprice=12000;
        if (strcmp("Colour Television",Prod_name)==0)
            Listprice=17000;
        if (strcmp(Prod_name,"Refrigerator")==0)
            Listprice=18000;
        if (strcmp(Prod_name,"OTG")==0)
            Listprice=8000;
        if (strcmp(Prod_name,"CD Player")==0)
            Listprice=4500;
        if(Dis_type=='F')
            percent=17;
        if(Dis_type=='N')
            percent=10;
        Distprice=(Listprice*percent)/100;
        Net=Listprice-Distprice;
    }

public:
    int  Accept()
    {
        cout<<"\n WELCOME TO CUSTOMER BILL GENERATION PROGRAM";
        cout<<"\n Enter product name ";
        gets(Prod_name);
        cout<<"\n Enter product  discount type ";
        cin>>Dis_type;
        Cal_price();
        return 0;
    }

    int ShowBill()
    {
        cout<<"\n BILL ";
        cout<<"\n Product purchased "<<Prod_name;
        cout<<"\n Net price "<<Listprice;
        cout<<"\n Dicount price "<<Distprice;
        cout<<"\n Net price after deduction "<<Net;
        return 0;
    }
};

int main()
{

    Departmental A;
    A.Accept();
    A.ShowBill();

    return 0;
}

Finally, getting to the program itself, well, not to put too fine a point on it, but it's terrible. You have completely misunderstood how to write a class in C++, and frankly, if this is what you were taught to do, your instructor should be barred from ever using a computer again.

The whole purpose of having objects to represent things is that each object should hold its own state. The way you have it, the closest thing you are coming to representing an object's state is for the store as a whol. This isn't how you write this sort of program, and it would be irresponsible of me not to give you a better solution.

What you want to do is have a class that describes the individual inventory items. I would recommend something along these lines:

enum discount_type {NONE = 0, N = 10, F = 17};

class Item
{
private:
    std::string name;
    int list_price;
    discount_type discount;

public:
    // constructor
    Item(std::string n, int p): name(n), list_price(p), discount(NONE)
    {
        return;
    }

    std::string get_name()
    {
        return name;
    }

    int get_price()
    {
       return list_price - (list_price * (discount / 100)); 
    };

    discount_type get_discount()
    {
        return discount_type;
    };

    void set_discount(discount_type dt)
    {
        discount = dt;
    };  
};

You could the have an array or list of Item objects, which would allow you to add or remove new Items as needed.

on running any program in dev c++ screen cannot hold and it close in very few second what i do for holding screen

on running any program in dev c++ screen cannot hold and it close in very few second what i do for holding screen

on running any program in dev c++ screen cannot hold and it close in very few second what i do for holding screen

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.