Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9248769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:01:21+00:00 2026-06-18T10:01:21+00:00

#include<iostream> #include <string> #include <fstream> #include <stdio.h> #include <stdlib.h> using namespace std; int optionChosen=0;

  • 0
#include<iostream>
#include <string>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int optionChosen=0;

struct bookStruct
{
    string bookTitle;
    int bookPageN;
    int bookReview;
    float bookPrice;
};

const int MAX_BOOKS=10;

int main()
{
    bookStruct books[10]={};


    do
    {
        cout << "Please Select an Option from the Menu:\n\n" << endl;
        cout << "1. Display List of Books.\n" << "2. Find Book.\n" << "3. Add New Book.\n";
        cout << "4. Delete Book.\n"<<"5. Save List to File.\n"<<"6. Load List from File.\n";
        cout << "7. Sort List.\n"<<"8. Exit.\n\n";
        cin >> optionChosen;
        switch(optionChosen)
        {
            case 1:
            {
                for (int i=0;i<MAX_BOOKS;i++)
                {
                    if(books[i].bookTitle!="\0")
                    {
                    cout << "Book Title: " << books[i].bookTitle << endl;
                    cout << "Total Pages: " << books[i].bookPageN << endl;
                    cout << "Book Review: " << books[i].bookReview << endl;
                    cout << "Book Price: " << books[i].bookPrice<< "\n\n" << endl;
                    }
                }
                break;
            }
        case 2:
        {

        }
        case 3:
        {
            for(int i=0;i<MAX_BOOKS;i++)
            {
                if(books[i].bookTitle=="\0")
                {
                cout << "\nPlease Enter the Title: ";
                cin >> books[i].bookTitle ;
                cout << "\nPlease Enter Total Number of Pages: ";
                cin >> books[i].bookPageN ;
                cout << "\nPlease Enter Rating (stars): ";
                cin >> books[i].bookReview ;
                cout << "\nPlease Enter Price: ";
                cin >> books[i].bookPrice;
                cout << "\n\nBook Added.\n\n";
                break;
                }
            }break;

        }
        case 4:
        {

        }
        case 5:
        {

        }
        case 6:
        {

        }
        case 7:
        {

        }
        default:
        {
            if(optionChosen!=8)
            {
                cout << "Wrong Input Chosen\n";
                break;
            }
        }

        }



    }
    while(optionChosen<=8);
    return 0;
}

Here is my code. 2 Question…..1. When I press anything that is not a number (a,b,c,abc) as an option, the program executes an infinite loop (maybe) and doesnt stop. Q#2. When I am adding a book, if I use space, the code does the same thing (executes possible infinite loop) and never stops. What am I doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:01:22+00:00Added an answer on June 18, 2026 at 10:01 am

    The first one is easy. When you cin >> some_int; and there’s no int in the input stream, it simply fails and leaves the input stream in its current state.

    That means the the next time you go back to get another int, it will still have the non-integer ready for reading.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<iostream> #include<stdlib.h> #include<string.h> #include<stdio.h> using namespace std; union type{ int a; char b; int
#include<stdio.h> #include<iostream> #include<fstream> #include<string.h> using namespace std; class base { public: int lookup(char c);
#include <iostream> #include <string> #include <fstream> using namespace std ; string strWord( int index
Here's my code so far: #include<iostream> #include<string> #include<fstream> using namespace std; int main() {
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { ifstream basketFile;
#include <iostream> #include <fstream> #include <string> using namespace std; int main (int argc, char*
#include <iostream> #include <string.h> using namespace std; int main() { int e=0; int b=0;
#include <iostream> #include <string> using namespace std; string crash() { } int noCrash() {
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) {
Given such a code segment: #include <iostream> #include <iterator> #include <fstream> #include <string> using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.