parallel array
I am trying to display a paired array.however am only displaying one side, can anyone help me here
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <iostream>
#include <cstring>
using namespace std;
const int MAXSIZE = 300;
void pause()
{
system("pause");
}
void listRecords(string allTitles[], double allPrices[], int totalRec)
{
int i,k;
totalRec = 2;
if(totalRec <= 0) cout << "* No book titles are available.\n";
else
{
cout << endl;
cout << "*** ALL AVAILABLE BOOK TITLES ***\n\n";
cout <<"TITLE PRICE ($)\n";
cout <<"-----------------------------------------\n";
//for (i=0; allTitles[i] < allTitles[MAXSIZE]; i++)cout << allTitles[i] <<"\n";
for (k =0; allPrices[k] < allPrices[MAXSIZE]; k++) cout << allPrices[k]<<"\n";
}
}
int main()
{
int totalRec = 2;
string allTitles[MAXSIZE] = {"Book 1", "Book 2"};
double allPrices[MAXSIZE] = {78.5, 66.0};
listRecords(allTitles,allPrices,totalRec);
//clrscr();
pause();
return 0;
}
| |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
void listRecords(string allTitles[], double allPrices[], int totalRec)
{
if(totalRec > 0)
{
cout << "\n*** ALL AVAILABLE BOOK TITLES ***\n\n";
cout <<"TITLE PRICE ($)\n";
cout <<"-----------------------------------------\n";
for (int i = 0; i < totalRec; ++i)
{
cout << allTitles[i] << ' ' << allPrices[i] << '\n';
}
}
else
{
cout << "* No book titles are available.\n";
}
}
| |
Topic archived. No new replies allowed.