I am in a bit of trouble with this code it is due tomorrow need pointers
the menu is displaying correctly but when i enter a number it locks up have i declared the switch statement wrong or is my menu declared incorrectly
also in regards to case 4 it is meant ot search to two arrays if a title is found delete it and the corresponding price so if element 1 stores the matching title then element 1 in the allPrices array is also cleared have i declared the removal correctly
// Book Price (16800960)
#include <iostream>
#include <string>
#include <iomanip>
const int MAXSIZE 300;
using namespace std;
void displayMenu ();
void listRecords(string allTitles[300], double allPrices[300], int totalRec);
string allTitles[MAXSIZE] = {
"Book 1",
"Book 2"
};
double allPrices[MAXSIZE] = {
78.5, 66.
};
int main ()
{
void displayMenu ();
cout << "MAIN MENU"<<"\n";cout<<endl;
cout << " 0. Exit " " 1. Enter Book " " 2. Find Book "<<"\n"; cout <<endl;
cout << " 3. List All " " 4. Delete Book" " 5. Update Book " << "\n"; cout <<endl;
string Title;
double Price;
int totalRec =2;
char menu;
cout << "Please Enter Menu Selection" ;
cin >> menu;
while (menu!=0);
switch (menu)
{
case '0' :
return 0;
break;
case '1' :
cout << " Enter Book Title";
cin >> Title >> allTitles [MAXSIZE];
cin >> Price >> allPrices [MAXSIZE];
totalRec = totalRec++ ;
break;
case '2' :
break;
case '3':
void listRecords(string allTitles[], double Prices[], int totalRec);
for (int i = 0; i < totalRec; i++)
cout << setw(15)
<< allTitles[i]
<< setw(15)
<< allPrices[i]
<< endl;
system ("pause");
break;
case '4':
string title;
cout << "Enter Title of the book record to delete ->";
getline(cin,title);
for(int i = 0; i < totalRec; i++)
{
if (title == allTitles[i])
{
for (int i ; i < totalRec; i++)
{
allTitles[i] = allTitles[i--];
allPrices[i] = allPrices[i--];
totalRec = (totalRec --);
cout << " Record Erased Successfully"; cout <<endl;
}
break;
break;
system ("pause"); }
}}
}
Sorry about the length of the program but i need to get the functions completed function 3 is declared correctly htough as i have this code in another program and it works.
for case 0 it is return 0 so it exits the program
case 1 is meant ot enter a new book hence i was thinking a getline cin, title << allTitles[TotalRec++]
getline cin price << to allprices [totalRec++]
with total rec at the top of the loop so that it is reinitialized when a new book is added
for case 5 it is meant to update the title or the price of the book i was thinking an embedded switch statement
which has 3 cases as follows
char
case 1
if char = b the whole book is edited
"" = t the title
"" =p the price only but is has to scan for the title to edit the corresponding price or search for the price by getting the titles position in all titles as they are storing the same number of records.
any help on this would be greatly appreciated even if i don't get the later functions completed though it would be good if it happens.
Thanks again.