Program won't Print a string array C++ -


i have been working on program awhile, refuses cooperate on last little stretch. point of program sift data file 3 arrays, sort arrays, print them out table. problem i'm having appears table. program divided 4 functions, , when attempt debug, won't show productname array in function.

the malfunctioning segment of code looks this:

void printreport (string productname[], int numberinstock[], float price[], int number_of_products) {     float totalprice;       cout << setw(18) << " " << "friendly grocer store inventory" << setw(17) << " " << endl;      cout << setw(18) << "inventory item" << setw(16) << "number in stock" << setw(16) << "unit price" << setw(16) << "total sales" << endl;      (int count=0; count <number_of_products-1; count++)     {         cout << setw(18) << productname[count] << setw(16) << numberinstock[count] << setw(16) << std::setprecision(2) << price[count] << setw(16) << std::fixed << std::setprecision(2) << price[count]*numberinstock[count] << endl;      }     cout << "total price:  " << totalprice;  } 

it print else, not productname. debugging statements outside of loop cout << productname[1] print out proper productname it's blank on actual report. after debugging seems after printing productname in loop every item after overwrites product name.

for example leaving cout << setw(18) << productname[count] << setw(16) << numberinstock[count] << endl;

will produce

" 3s"
" 10h"
" 2a"

the product names there mangoes, sandwich, , pizza.

i'm @ loss. did mess up?

you might have screwed passing data function. if set test arrays in function should printing correctly.

to pass arrays in c++ use arrayname. eg

int main () {   string productname[] = {"mango"};    ...   printreport(productname, numofproduct);   return 0; } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -