I have to create a program with parallele arrays that recieves information from a file telling it how many salsas their are (their can't be more than 10). One array containts the name of the salsa, the other array contains the number of salsa jars sold. Then I have to print the data. I'm not sure why but I keep having alot of problems. If anyone could help me out I would appreciate it.

Thanks, ACRobison02

#include <iostream>
using namespace std;

int getSalsaData (string [], int[]);
void DisplaySalsa (string [], int []);

int main ()
{
const int max = 10;
string salsa[max];
int numsold[max];
int numsalsa;

numsalsa=getSalsaData (salsa, numsold);
DisplaySalsa (salsa, numsold);

return 0;
}

int getSalsaData(string salsa[max], int numsold [max])
{
  int numsalsa;
  cin>>numsalsa;

     for (int k=0; k<max; k++)
     {
     cin>>salsa[k];
     cin>>numsold[k];
     }
return numsalsa;
  }

void DisplaySalsa(string salsa[max], int numsold[max])
{
  cout<<"Salsa Type      Jars Sold " <<endl;

  for (int k=0; k<max; k++)
     {
     cin>>salsa[k];
     cin>>numsold[k];
     }
}

Recommended Answers

All 4 Replies

>> I'm not sure why but I keep having alot of problems.
What are the problems? Error messages? compiler you are using? Operating system ?

You need to include a string command.

Add #include <string.h>

void DisplaySalsa(string salsa[], int numsold[])
{
  cout<<"Salsa Type      Jars Sold " <<endl;

  for (int k=0; k<max; k++)
     {
     cout<<"salsa["<<k<<"] = "<<salsa[k]<<endl;
     cout<<"numsold["<<k<<"] = "<<numsold[k]<<endl;
     }
}
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.