Bookshelf Data Structures IssuesTree data structure in C#What are the lesser known but useful data structures?Java tree data-structure?Vector C++ , whats wrong with getting the 2nd element of vectorError: No match for 'operator<<' and 'operator>>'. Help please?How to terminate cin>> input with specific word/letter/number/etcWhy does const does not works with size() for stl map, whereas it works perfectly for other containers ?C++ Invalid entry error detector for menu programconcatenating a Hexadecimal number with zerosInput inside while and vectors

Does Assassinate grant two attacks?

Ability To Change Root User Password (Vulnerability?)

The Frozen Wastes

How to communicate to my GM that not being allowed to use stealth isn't fun for me?

Increase speed altering column on large table to NON NULL

If I leave the US through an airport, do I have to return through the same airport?

Proving that a Russian cryptographic standard is too structured

Which is the better way to call a method that is only available to one class that implements an interface but not the other one?

Can the removal of a duty-free sales trolley result in a measurable reduction in emissions?

How can one's career as a reviewer be ended?

Should I refuse being named as co-author of a bad quality paper?

Origin of "boor"

Is using 'echo' to display attacker-controlled data on the terminal dangerous?

How creative should the DM let an artificer be in terms of what they can build?

I have a problematic assistant manager, but I can't fire him

Is it safe to change the harddrive power feature so that it never turns off?

Why are MBA programs closing?

Why can my keyboard only digest 6 keypresses at a time?

How can I remove material from this wood beam?

Why did my credit score plummet after a balance transfer?

With Ubuntu 18.04, how can I have a hot corner that locks the computer?

How do photos of the same subject compare between the Nikon D700 and D70?

Does the new finding on "reversing a quantum jump mid-flight" rule out any interpretations of QM?

std::declval vs crtp, cannot deduce method return type from incomplete type



Bookshelf Data Structures Issues


Tree data structure in C#What are the lesser known but useful data structures?Java tree data-structure?Vector C++ , whats wrong with getting the 2nd element of vectorError: No match for 'operator<<' and 'operator>>'. Help please?How to terminate cin>> input with specific word/letter/number/etcWhy does const does not works with size() for stl map, whereas it works perfectly for other containers ?C++ Invalid entry error detector for menu programconcatenating a Hexadecimal number with zerosInput inside while and vectors






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I am making a bookshelf of width size s(1<s<100). Add book id and the book width at the leftmost of the vector. If you add a book which causes the width to be exceeded, then delete the rightmost book until the book to be added can be put on the shelf. In the end, the remaining books on the bookshelf can be added.



The issue I am facing that when var = 'E' the program should display the remaining books on the shelf and then exit that problem and go to a different problem, but when 'E' is entered the remaining books on the shelf will not display, and the program will not exit. I have tried messing with the while loops condition that is nested in the overall while loop.



#include <iostream>
#include <vector>

using namespace std;

struct book
int id;
int w;
;

int main()
//std::vector::~vector
//create instance of book
book my_book;
//initialize the placeholders
int s, removed_book, back_width;
char var;
//create the vector
vector<book>shelf;
while(true)
//enter the s value
s = 0;
cout << "enter the s value: " << endl;
cin >> s;
int w_total = 0;

//be able to exit the program
if(s == -1)
return 0;

int x = 1;
//while remaining space
while(x!=0) //need to fix this up

cout << "enter the action(A,R,E): " << endl;
cin >> var >> my_book.id >> my_book.w;


//if A
if(var == 'A')
//get info about the book
/*
cout << "enter id: " << endl;
cin >> my_book.id;
cout << "width(w): " << endl;
cin >> my_book.w;
*/
w_total += my_book.w;
shelf.insert(shelf.begin(),my_book);
cout << "total width(1): " << w_total << endl;

if(w_total > s)
while(w_total >= s)
//remove the rightmost(back) book
w_total = w_total - shelf.back().w;
cout << "total width(2): " << w_total << endl;
shelf.erase(shelf.end()-1);



//if R
else if(var == 'R')
//cout << "which book to be removed? : " << endl;
//cin >> removed_book;
removed_book = my_book.id;
for(int i = 0; i < s; i++)
if(shelf[i].id == removed_book)
shelf.erase(shelf.begin()+i);



//if E
else if(var == 'E')
cout << "remaining books on shelf: " << endl;
for(int i = 0; i < shelf.size(); i++)
if(shelf[i].id!=0)
cout << "id: "<<shelf[i].id << endl;


//maybe put the display in here?
x = 1;


//print out the remaining shelf

shelf.clear();
//erase the shelfs(vectors) contents
//increase problem number

return 0;



Expected output:



10(shelf width)
A 1 3(Add id width)
A 2 5
E
-->PROBLEM 1: 2 1









share|improve this question






























    1















    I am making a bookshelf of width size s(1<s<100). Add book id and the book width at the leftmost of the vector. If you add a book which causes the width to be exceeded, then delete the rightmost book until the book to be added can be put on the shelf. In the end, the remaining books on the bookshelf can be added.



    The issue I am facing that when var = 'E' the program should display the remaining books on the shelf and then exit that problem and go to a different problem, but when 'E' is entered the remaining books on the shelf will not display, and the program will not exit. I have tried messing with the while loops condition that is nested in the overall while loop.



    #include <iostream>
    #include <vector>

    using namespace std;

    struct book
    int id;
    int w;
    ;

    int main()
    //std::vector::~vector
    //create instance of book
    book my_book;
    //initialize the placeholders
    int s, removed_book, back_width;
    char var;
    //create the vector
    vector<book>shelf;
    while(true)
    //enter the s value
    s = 0;
    cout << "enter the s value: " << endl;
    cin >> s;
    int w_total = 0;

    //be able to exit the program
    if(s == -1)
    return 0;

    int x = 1;
    //while remaining space
    while(x!=0) //need to fix this up

    cout << "enter the action(A,R,E): " << endl;
    cin >> var >> my_book.id >> my_book.w;


    //if A
    if(var == 'A')
    //get info about the book
    /*
    cout << "enter id: " << endl;
    cin >> my_book.id;
    cout << "width(w): " << endl;
    cin >> my_book.w;
    */
    w_total += my_book.w;
    shelf.insert(shelf.begin(),my_book);
    cout << "total width(1): " << w_total << endl;

    if(w_total > s)
    while(w_total >= s)
    //remove the rightmost(back) book
    w_total = w_total - shelf.back().w;
    cout << "total width(2): " << w_total << endl;
    shelf.erase(shelf.end()-1);



    //if R
    else if(var == 'R')
    //cout << "which book to be removed? : " << endl;
    //cin >> removed_book;
    removed_book = my_book.id;
    for(int i = 0; i < s; i++)
    if(shelf[i].id == removed_book)
    shelf.erase(shelf.begin()+i);



    //if E
    else if(var == 'E')
    cout << "remaining books on shelf: " << endl;
    for(int i = 0; i < shelf.size(); i++)
    if(shelf[i].id!=0)
    cout << "id: "<<shelf[i].id << endl;


    //maybe put the display in here?
    x = 1;


    //print out the remaining shelf

    shelf.clear();
    //erase the shelfs(vectors) contents
    //increase problem number

    return 0;



    Expected output:



    10(shelf width)
    A 1 3(Add id width)
    A 2 5
    E
    -->PROBLEM 1: 2 1









    share|improve this question


























      1












      1








      1








      I am making a bookshelf of width size s(1<s<100). Add book id and the book width at the leftmost of the vector. If you add a book which causes the width to be exceeded, then delete the rightmost book until the book to be added can be put on the shelf. In the end, the remaining books on the bookshelf can be added.



      The issue I am facing that when var = 'E' the program should display the remaining books on the shelf and then exit that problem and go to a different problem, but when 'E' is entered the remaining books on the shelf will not display, and the program will not exit. I have tried messing with the while loops condition that is nested in the overall while loop.



      #include <iostream>
      #include <vector>

      using namespace std;

      struct book
      int id;
      int w;
      ;

      int main()
      //std::vector::~vector
      //create instance of book
      book my_book;
      //initialize the placeholders
      int s, removed_book, back_width;
      char var;
      //create the vector
      vector<book>shelf;
      while(true)
      //enter the s value
      s = 0;
      cout << "enter the s value: " << endl;
      cin >> s;
      int w_total = 0;

      //be able to exit the program
      if(s == -1)
      return 0;

      int x = 1;
      //while remaining space
      while(x!=0) //need to fix this up

      cout << "enter the action(A,R,E): " << endl;
      cin >> var >> my_book.id >> my_book.w;


      //if A
      if(var == 'A')
      //get info about the book
      /*
      cout << "enter id: " << endl;
      cin >> my_book.id;
      cout << "width(w): " << endl;
      cin >> my_book.w;
      */
      w_total += my_book.w;
      shelf.insert(shelf.begin(),my_book);
      cout << "total width(1): " << w_total << endl;

      if(w_total > s)
      while(w_total >= s)
      //remove the rightmost(back) book
      w_total = w_total - shelf.back().w;
      cout << "total width(2): " << w_total << endl;
      shelf.erase(shelf.end()-1);



      //if R
      else if(var == 'R')
      //cout << "which book to be removed? : " << endl;
      //cin >> removed_book;
      removed_book = my_book.id;
      for(int i = 0; i < s; i++)
      if(shelf[i].id == removed_book)
      shelf.erase(shelf.begin()+i);



      //if E
      else if(var == 'E')
      cout << "remaining books on shelf: " << endl;
      for(int i = 0; i < shelf.size(); i++)
      if(shelf[i].id!=0)
      cout << "id: "<<shelf[i].id << endl;


      //maybe put the display in here?
      x = 1;


      //print out the remaining shelf

      shelf.clear();
      //erase the shelfs(vectors) contents
      //increase problem number

      return 0;



      Expected output:



      10(shelf width)
      A 1 3(Add id width)
      A 2 5
      E
      -->PROBLEM 1: 2 1









      share|improve this question
















      I am making a bookshelf of width size s(1<s<100). Add book id and the book width at the leftmost of the vector. If you add a book which causes the width to be exceeded, then delete the rightmost book until the book to be added can be put on the shelf. In the end, the remaining books on the bookshelf can be added.



      The issue I am facing that when var = 'E' the program should display the remaining books on the shelf and then exit that problem and go to a different problem, but when 'E' is entered the remaining books on the shelf will not display, and the program will not exit. I have tried messing with the while loops condition that is nested in the overall while loop.



      #include <iostream>
      #include <vector>

      using namespace std;

      struct book
      int id;
      int w;
      ;

      int main()
      //std::vector::~vector
      //create instance of book
      book my_book;
      //initialize the placeholders
      int s, removed_book, back_width;
      char var;
      //create the vector
      vector<book>shelf;
      while(true)
      //enter the s value
      s = 0;
      cout << "enter the s value: " << endl;
      cin >> s;
      int w_total = 0;

      //be able to exit the program
      if(s == -1)
      return 0;

      int x = 1;
      //while remaining space
      while(x!=0) //need to fix this up

      cout << "enter the action(A,R,E): " << endl;
      cin >> var >> my_book.id >> my_book.w;


      //if A
      if(var == 'A')
      //get info about the book
      /*
      cout << "enter id: " << endl;
      cin >> my_book.id;
      cout << "width(w): " << endl;
      cin >> my_book.w;
      */
      w_total += my_book.w;
      shelf.insert(shelf.begin(),my_book);
      cout << "total width(1): " << w_total << endl;

      if(w_total > s)
      while(w_total >= s)
      //remove the rightmost(back) book
      w_total = w_total - shelf.back().w;
      cout << "total width(2): " << w_total << endl;
      shelf.erase(shelf.end()-1);



      //if R
      else if(var == 'R')
      //cout << "which book to be removed? : " << endl;
      //cin >> removed_book;
      removed_book = my_book.id;
      for(int i = 0; i < s; i++)
      if(shelf[i].id == removed_book)
      shelf.erase(shelf.begin()+i);



      //if E
      else if(var == 'E')
      cout << "remaining books on shelf: " << endl;
      for(int i = 0; i < shelf.size(); i++)
      if(shelf[i].id!=0)
      cout << "id: "<<shelf[i].id << endl;


      //maybe put the display in here?
      x = 1;


      //print out the remaining shelf

      shelf.clear();
      //erase the shelfs(vectors) contents
      //increase problem number

      return 0;



      Expected output:



      10(shelf width)
      A 1 3(Add id width)
      A 2 5
      E
      -->PROBLEM 1: 2 1






      c++ vector data-structures






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 19:54









      Yunnosch

      11.7k52334




      11.7k52334










      asked Mar 24 at 19:49









      Frank Schroer IVFrank Schroer IV

      61




      61






















          1 Answer
          1






          active

          oldest

          votes


















          2














          cin >> var >> my_book.id >> my_book.w is asking the user to enter three things: a character and two integers. You have to enter all three before the action in var will be checked and acted upon.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55327893%2fbookshelf-data-structures-issues%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            cin >> var >> my_book.id >> my_book.w is asking the user to enter three things: a character and two integers. You have to enter all three before the action in var will be checked and acted upon.






            share|improve this answer



























              2














              cin >> var >> my_book.id >> my_book.w is asking the user to enter three things: a character and two integers. You have to enter all three before the action in var will be checked and acted upon.






              share|improve this answer

























                2












                2








                2







                cin >> var >> my_book.id >> my_book.w is asking the user to enter three things: a character and two integers. You have to enter all three before the action in var will be checked and acted upon.






                share|improve this answer













                cin >> var >> my_book.id >> my_book.w is asking the user to enter three things: a character and two integers. You have to enter all three before the action in var will be checked and acted upon.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 24 at 19:53









                1201ProgramAlarm1201ProgramAlarm

                19.8k72741




                19.8k72741





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55327893%2fbookshelf-data-structures-issues%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현