}
case 2:
{
system("cls");
cout<<"Choose Physics books from The List below: "<<endl<<endl;
cout<<"1.Physics 1"<<endl<<endl;
cout<<"2.Physics 2"<<endl<<endl;
cout<<"3.Physics 3"<<endl<<endl;
cout<<"4.Physics 4"<<endl<<endl;
cout<<"5.Physics 5"<<endl<<endl;
cout<<"6.Return"<<endl<<endl;
cin>>numbc;
switch (numbc)
{
case 1:
{
i++;
booktitles[i]="physic1";
break;
}
case 2:
{
i++;
booktitles[i]="physic 2";
break;
}
case 3:
{
i++;
booktitles[i]="physic 3";
break;
}
case 4:
{
i++;
booktitles[i]="physic 4";
break;
}
case 6:
{
system("cls");
goto loop;
break;
}
}
break;
break;
}
case 5:
{
return 0;
break;
}
}
system("cls");
}while (numchosen<5);
cout<<"Please reenter the book you want to choose:"<<endl<<endl;
goto loop;
system("PAUSE");
return EXIT_SUCCESS;
}
half way done.. my problem is how to show the user the list of book from which the user want and the book list show again after the user choose another book..
p/s book chosen cannot be display anymore...
any idea about it?
due the characters are over 9000, therefore i have skipped the case 5,6, just help me think about the mathematics.. when i choose Math1, the book title showed math1(that's right), but when i choose math2 for next choice, the book titles will show no1. math2..... no2. math2... the previous math1 are replaced by math2...
Error: you're not #including <string>, which you need to use C++ strings, which you are using.
For your problem, I recommend creating a vector of book names. Have an infinite while loop that terminates when you choose the option to show something else than that section (do not use goto, it's dangerous). When you need to delete a book from the list, call vector.erase(vector.begin() + selection - 1) (assuming selection cannot be zero). Here's a few snippets to better understand vectors:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <vector>
//You'll need to do that at the top of your file to use vectors. Note that vectors are part of the namespace std.
vector<type> name; //Creates a vector of type... type.
//A vector is really not much more than a glorified array with functions that can change its own size.
name.at(int array-like_position); //Fetches an element from the vector.
//This is a vector equivalent of an array's [] except that it's safer.
//(if you go out of bounds using .at(), you get an error, this may or may not happen with an array).
name.push_back(type to_append); //Appends an element to a vector, expanding the vector as needed.
//Nifty, you'll want to use this all the time.
name.erase(name.begin() + unsignedint offset); //Erases the first element from the vector...
//...which can be changed by adding a non-zero integer.
//name.begin() sets an internal iterator in the vector to the first element. Adding an integer to that iterator moves it.
name.clear(); //Erases the contents of the whole vector.