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.

I'll offer the same advice as before. You have your working function now, so get your menu function working independently and add things in one by one, compiling in between.

Line 40 is not going to do anything. Lines 50 and 51 are going to overrun the array bounds. On 79 you don't initialize i. I would rethink your approach on 81 and 82 a bit, since your i-- is a postfix operation.

So it is better to just switch the menu and have it exit when 0 is entered

clears up line 40 for 50 and 51 would it be better to define it against totalrec as if a new title is entered using the enter function then it would make it reloop unless i an exit clause maybe


with 81 and 82 i am unsure on the delete record but you are right i can get it working somehow

is there a better way to delete the records i know i could define a simple function if matched element is selected then value for i was pos 3 then = i=2

something like that i haven't dealt with a delete function before


why did i put two breaks at the end i should have case 5:

= break ;

exit the switch maybe with a default = 0;

with a cout please hit return to exit


and remove line 79; as i have a for loop already

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.