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 8986963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:40:38+00:00 2026-06-15T21:40:38+00:00

this is a project I’m working on which comes from the book I’m using

  • 0

this is a project I’m working on which comes from the book I’m using to learn C++ – “Starting out with C++”. I’m having a problem with the cashier portion of the project at the moment. It asks the user to enter the date, quantity, isbn, title, and price of the book. Then, it asks the user if they wish to enter another book. Regardless of whether they type “y” or “n” it continues to the next part of the program. I don’t really know why the for loop doesn’t repeat after I type “y” to enter another book. Also, the date is coming out with garbage at the end when it is displayed, that’s another thing I need to fix. Any help would be appreciated. There is definitely more problems but the main problem is in the cashier function in the first for loop. I didn’t include the whole program because it’s very long.

/*
 *  mainmenu.cpp
 *  Serendipity Booksellers software
 *
 *  Created by Abraham Quilca on 9/5/12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */


#include<iostream>
#include<iomanip>
#include<cstring>
#include"mainmenu.h"
using namespace std;

char bookTitle[20][51],
 isbn[20][14],
 author[20][31],
 publisher[20][31],
 dateAdded[20][11];
int qtyOnHand[20];
double wholesale[20];
double retail[20];;

int main()
{
    int choice;

do
{
    cout << "\t\t   Serendipity Booksellers"<< endl;
    cout << "\t\t\t  Main Menu" << endl << endl;
    cout << "\t\t1. Cashier Module" << endl;
    cout << "\t\t2. Inventory Database Module" << endl;
    cout << "\t\t3. Report Module" << endl;
    cout << "\t\t4. Exit" << endl << endl;
    cout << "\t\tEnter your choice: ";
    cin >> choice;
    cout << endl;
    switch (choice)
    {
        case 1:
            cashier();
            break;
        case 2:
            invmenu();
            break;
        case 3:
            reports();
            break;
        case 4:
            continue;
            break;
        default:
            cout << "\t\tPlease enter a number in the range 1-4." << endl << endl;
    }
}   
while(choice != 4);
cout << "\t\tYou selected item 4." << endl;
return 0;
}

// Cashier function

void cashier()
{
    char again;
    char date[8];
    int quantity[20] = {0};
    char ISBN[20][20] = {0};
    char title[20][40] = {0};
    float price[20] = {0}, bookTotal[20] = {0}, subtotal, total, tax;
    const float tax_rate = .06;

    cout << "Serendipity Booksellers" << endl;
    cout << " Cashier Module" << endl << endl;

    for(int count = 0; count < 20; count++)
    {
        cout << "Date: ";
        cin >> date;
        cout << "Quantity of Book: ";
        cin >> quantity[count];
        cout << "ISBN: ";
        cin >> ISBN[count];
        cout << "Title: ";
        cin.ignore();
        cin.getline(title[count], 40);
        cout << "Price: ";
        cin >> price[count];
        bookTotal[count] = quantity[count] * price[count];
        subtotal += price[count];
        cout << "Would you like to enter another book? (Y/N) ";
        cin >> again;
        if(again == 'N' || 'n')
            count = 21; // This line will end the for loop
    }
    // Calculating tax and total
    tax = subtotal * tax_rate;
    total = subtotal + tax;

    cout << "\n\nSerendipity Booksellers" << endl << endl;
    cout << "Date:" << date << endl << endl;
    cout << "Qty\t ISBN\t\t "
        << left << setw(40) << "Title" << "Price\t Total" << endl
        <<     "-------------------------------------------------------------------------------"
        << endl << endl;
    for(int count = 0; count < 20; count++)
    {
        cout << quantity[count] << "\t " << ISBN[count] << "   " << left << setw(40) << title[count] 
        << setprecision(2) << fixed << "$" << setw(6) << price[count] << " $" << setw(6) << bookTotal[count]
        << endl << endl;
    }
    cout << "\t\t\t Subtotal" << "\t\t\t\t         $" << setw(6) << subtotal << endl;
    cout << "\t\t\t Tax" << "\t\t\t\t                 $" << setw(6) << tax<< endl;
    cout << "\t\t\t Total" "\t\t\t\t                 $" << setw(6) << total << endl << endl;
    cout << "Thank You for Shopping at Serendipity!" << endl << endl;
}
  • 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-15T21:40:39+00:00Added an answer on June 15, 2026 at 9:40 pm
    if(again == 'N' || 'n')
    

    This doesn’t do what you think it does. Look at it like this:

    if((again == 'N') || ('n'))
    

    Is again == N true OR is n true? Well n will always be true (it is a char with non-zero value) so your loop will always end immediately. What you want is:

    if(again == 'N' || again == 'n')
    

    Also, you can break out of a loop using the aptly named break keyword:

    if (again == 'N' || again == 'n') {
      break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So this was working on this project a few months ago. I'm using Google
This samplet is from a project I am working on. My client uses software
I am working on this project. There is a class DefaultsHelper which has :
This project was coped almost exacatly from the example on the admob page but
This project is in Obj-C for iphone. I'm using the double float version of
I am working on this project where I wish to classify the general mood
I'm working on this project where the client has a virtual server setup. I
This project consists of a single .cpp file which calls LoadLibrary() to load a
For this project I'm working on, I want to take multiple excel sheets and
I have this project set up with EF4 and I'm using LINQ to Entities

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.