I'm trying to use a structure in my c++ project but I've run into a bit of a problem. In my project I create a create a dynamic array after asking the user how many people that have done sales and how many days they worked. After that the program goes through a for loop to in put the data. Here the user is asked to enter names of the people and it then asks the number of units pre day until the a second for loop reaches the max number of days that the user inputted therein lies my problem. I tried using a two dimensional dynamic array put the program kept crashing so I'm not sure what I'm doing wrong. Here is my code:
#include <iostream>
#include <string>
struct emp{
string names;
int *untsold;
};
int main(){
int people;
int days;
emp *workers;
cout<<"How many workers are we looking at?"<<endl;
cin>>people;
cout<<"How many days are we looking at?"<<endl;
cin>>days
workers = new emp[people,days];
for(int index=0;index<people;index++){
cin.ignore();
cout<<"Enter the name of worker number "<<index+1<<"."<<endl;
getline(cin,emp[index,0].names);
for(int index2=0;index2<days;index++){
cout<<"Now enter the number of units sold on day "<<index2+1<<endl;
cin>>*workers[index,index2].untsold;
}
}
}
The rest of the program is just displaying the information in a table then delete the dynamic array. The program seems crash right after I enter in something for the *workers[index,index2].untsold variable. Is it possible to put an array of variables within a dynamic array or should I try something else. Please mind that my teacher wants me to use both structure variables and dynamic arrays also note that I'm a beginner.
workers[index,index2]?new emp[people,days]? This isn't C++.