Hello Everyone,

Off the bat I want to say that I am just learning programming so if my code is missing basics I apologize. I was hoping that you might be able to give me an example of how you would solve this problem. I've spent the better part of a week now wracking my brain over this.

I have to answer this problem:
Assume that you have the following definition of a struct:

struct partsType 
{ 
String partName; 
Int partNum; 
double price; 
int quantitiesInStock; 
}; 

Declare an array, inventory, of 100 components of type partsType.

Now take above struct definition above and:
1.Write a C++ code to initialize each component of inventory as follows: part name to null string, partNum to -1, price to 0.0 and quantities in quantitiesInStock to 0. .
2.Write a C++ code that uses a loop to output the data stored in inventory. Assume that the variable length indicates the number of elements in inventory.

I have developed to this point:

#include <iostream>  //Declares IO Stream
using namespace std; //Declares Namespace

for (int i = 0; i < 100; i++) //Declares Counter

    { 

        inventory[i].partName = ""; //Sets partName = to part

        inventory[i].partNum = -1; //Sets partNum counter = -1

        inventory[i].price = 0.0; //Sets price = 0.0

        inventory[i].quantitiesInStock = 0; //Sets counter for quantity to zero.

    } 
 for (int i = 0; i < length; i++) 

    { 

        cout << inventory[i].partName << endl; //Output for Part Number

        cout << inventory[i].partNum << endl; //Output for Part Number

        cout << inventory[i].price << endl; //Output for Price

        cout << inventory[i].quantitiesInStock << endl; //Output for quantities

    } 
 system "pause";
 return 0;

Any help you may provide is greatly appreciated!!!

Neil

You don't seem to have a main function.

You are trying to use the array inventory without having actually created it.

system("pause") is hideous and expensive and dangerous and non-portable. http://www.gidnetwork.com/b-61.html

Is this a little better in the right direction?

#include <iostream>  //Declares IO Stream
using namespace std; //Declares Namespace
int main ()
{

    int partName;
    int partNum;
    int price;
    int quantitiesInStock;
    int inventory;

    int arr[100];
for (int i = 0; i < 100; i++) //Declares Counter

    { 

        inventory[i].partName = ""; //Sets partName = to part

        inventory[i].partNum = -1; //Sets partNum counter = -1

        inventory[i].price = 0.0; //Sets price = 0.0

        inventory[i].quantitiesInStock = 0; //Sets counter for quantity to zero.

    } 
 for (int i = 0; i < length; i++) 

    { 

        cout << inventory[i].partName << endl; //Output for Part Number

        cout << inventory[i].partNum << endl; //Output for Part Number

        cout << inventory[i].price << endl; //Output for Price

        cout << inventory[i].quantitiesInStock << endl; //Output for quantities

    } 

 return 0;
}
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.