{




 #include "stdafx.h"
 #include <iostream.h>
 #include <stdio.h>
 #include <string.h>
 class inventory
 {
 private:
 int prodID;
 char prodDescription[20];
 int qtyInStock;
 public:
 inventory()//default constructor
 {
 prodID=0;
 strcpy(prodDescription,"-");
 qtyInStock=0;
 }
 inventory(int a,char *b,int c) //constructor that initializes a new Inventoryobjects with the values passed as arguments
 {
 prodID=a;
 strcpy(prodDescription,b);
 qtyInStock=c;
 }
 };
 int main(int argc, char* argv[])
 {
 inventory obj(1,"cotton tshirt",4);
 return 0;
 }
 Please Im not trying to get my homewotk done, just to understand my errors.
 It complies without problem. But doesn't run.
 Thanks again.

You say that the code compiles without problem, but I can see an extraneous open brace at the top of the code which would be a showstopper. This may simply be an artifact of copying the code to the forum, however.

I recommend you indent your code effectively, according to a style you find aesthetically pleasing and helpful; the specific style doesn't matter much, so long as you apply some sort of indentation, and are consistent in using the same style across the board. Here is your code again, suitably indented in Allman style (sans the extra brace at the top, and the unneeded Microsoft pre-compiled header, and with the modern headers for the remaining ones):

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

class inventory
{
private:
    int prodID;
    char prodDescription[20];
    int qtyInStock;

public:
    inventory() //default constructor
    {
        prodID = 0;
        strcpy(prodDescription,"-");
        qtyInStock = 0;
    }

    inventory(int a, char *b, int c) //constructor that initializes a new Inventoryobjects with the values passed as arguments
    {
        prodID = a;
        strcpy(prodDescription,b);
        qtyInStock = c;
    }
};

int main(int argc, char* argv[])
{
    inventory obj(1,"cotton tshirt",4);
    return 0;
}

I assume that you are using Visual C++ for this, given the use of the <stdafx.h> header. Can you tell us the version you are using? The use of the older style headers (e.g., <iostream.h> rather than <iostream>, <stdio.h> instead of <cstdio>) should have raised a warning with any recent versions of the compiler. Do you know what level of warnings you have it set to?

Looking at the code, I don't see any evidence of any kind of output from the program. This means that even if it ran correctly, it wouldn't have any visible effect. Just what is happening when you try to run it? Does it give an error such as a segmentation violation, or simply run without any output (as would be expected in this case)?

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.