Array/Function problems

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 3
Reputation: ACRobison02 is an unknown quantity at this point 
Solved Threads: 0
ACRobison02 ACRobison02 is offline Offline
Newbie Poster

Array/Function problems

 
0
  #1
Dec 4th, 2008
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

  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int getSalsaData (string [], int[]);
  6. void DisplaySalsa (string [], int []);
  7.  
  8. int main ()
  9. {
  10. const int max = 10;
  11. string salsa[max];
  12. int numsold[max];
  13. int numsalsa;
  14.  
  15. numsalsa=getSalsaData (salsa, numsold);
  16. DisplaySalsa (salsa, numsold);
  17.  
  18. return 0;
  19. }
  20.  
  21. int getSalsaData(string salsa[max], int numsold [max])
  22. {
  23. int numsalsa;
  24. cin>>numsalsa;
  25.  
  26. for (int k=0; k<max; k++)
  27. {
  28. cin>>salsa[k];
  29. cin>>numsold[k];
  30. }
  31. return numsalsa;
  32. }
  33.  
  34. void DisplaySalsa(string salsa[max], int numsold[max])
  35. {
  36. cout<<"Salsa Type Jars Sold " <<endl;
  37.  
  38. for (int k=0; k<max; k++)
  39. {
  40. cin>>salsa[k];
  41. cin>>numsold[k];
  42. }
  43. }
Last edited by Ancient Dragon; Dec 4th, 2008 at 11:49 pm. Reason: add line numbers
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,609
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Array/Function problems

 
0
  #2
Dec 4th, 2008
>> I'm not sure why but I keep having alot of problems.
What are the problems? Error messages? compiler you are using? Operating system ?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 17
Reputation: StainlessSteelR is an unknown quantity at this point 
Solved Threads: 0
StainlessSteelR StainlessSteelR is offline Offline
Newbie Poster

Re: Array/Function problems

 
0
  #3
Dec 5th, 2008
You need to include a string command.
Last edited by StainlessSteelR; Dec 5th, 2008 at 1:58 am. Reason: Mistype
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 160
Reputation: dmanw100 is on a distinguished road 
Solved Threads: 12
dmanw100's Avatar
dmanw100 dmanw100 is offline Offline
Junior Poster

Re: Array/Function problems

 
0
  #4
Dec 5th, 2008
Add #include <string.h>
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 338
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 66
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Array/Function problems

 
0
  #5
Dec 5th, 2008
  1. void DisplaySalsa(string salsa[], int numsold[])
  2. {
  3. cout<<"Salsa Type Jars Sold " <<endl;
  4.  
  5. for (int k=0; k<max; k++)
  6. {
  7. cout<<"salsa["<<k<<"] = "<<salsa[k]<<endl;
  8. cout<<"numsold["<<k<<"] = "<<numsold[k]<<endl;
  9. }
  10. }
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC