I have a problem to solve where I need to show the output in this format:
But the problem I am facing is that for Purchase ID: 2, which has two book title, the second book title (Midnight Library) is shown in second line and does not align properly, how can I align it under the Book Title?
Code:
void viewPurchase() //View all purchase transactions
{
system("cls");
struct purchaseInfo* viewPurchase;
viewPurchase = head;
int choice;
cout << "*************" << endl;
cout << "VIEW PURCHASE" << endl;
cout << "*************" << endl;
cout << "1. View Purchase" << endl;
cout << " " << endl;
cout << "0. BACK TO MENU" << endl;
cout << "\nEnter your choice: ";
cin >> choice;
switch (choice)
{
case 1:
{
if (viewPurchase == NULL) {
cout << "No record in the list\n";
cout << "\nPress ENTER to Back to Menu...\n" << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.get();
}
while (viewPurchase != NULL) {
cout << "============================================================================\n";
cout << "Purchase ID \tBook Title \t\t Total Item \tTotal Price\n";
cout << "============================================================================\n";
while (viewPurchase != NULL) {
cout << left << setw(16) << viewPurchase->purchaseID;
for (int loop = 0; loop < viewPurchase->size; loop++) {
cout << left << setw(30) << viewPurchase->book[loop].bookTitle;
if (loop == 0) {
cout << left << setw(18) << viewPurchase->totalItem;
cout << left << setw(16) << viewPurchase->totalPrice;
}
cout << endl;
}
viewPurchase = viewPurchase->next;
}
}
break;
}
case 0:
break;
default:
cout << "\nInvalid selection. Press ENTER to continue...\n" << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.get();
break;
}
};
Anything need to change for this code?
cout << left << setw(30) << viewPurchase->book[loop].bookTitle;
but the second book title (Midnight Library) run away and does not align properly, how can I align it under the book Title?
Insert an empty string, using setw matching the width of the first column before inserting the book title.
Related
I am writing a "vending machine/grocery shopping" code in C++ where I have a menu of 5 items and the user can choose to add as my items as they want. The price is calculated at the end.
Since the user can add as many items they want, I used a while loop to so they can "continue shopping." However, I was not able to successfully do this because they code would keep running. I tried to put the switch statement in a function but did not call the "reply" properly.
Could someone help me with this code, specifically the while loop and switch statement function called int shoppingCart(). If someone could help me with abstracting this code that would be great!)
Code below (this is the original, I put an edited one below):
#include <iostream>
using namespace std;
void vendingMachine() {
cout << "1. Popcorn: $2" << endl;
cout << "2. Coconut Clusters: $3" << endl;
cout << "3. Granola Bar: $2.50" << endl;
cout << "4. Trail Mix: $1.50" << endl;
cout << "5. Chocolate: $1" << endl;
cout << "Press 0 to checkout" << endl;
}
int main() {
cout << "Vending Machine" << endl;
cout << "----Items------" << endl;
vendingMachine();
cout << "Enter you selection: " << flush;
int input;
cin >> input;
float cost;
switch (input) {
case 1:
cout << "You added Popcorn to your cart." << endl;
cost = 2;
break;
case 2:
cout << "You added Coconut Clusters to your cart." << endl;
cost = 3;
break;
case 3:
cout << "You added Granola Bar to your cart." << endl;
cost = 2.50;
break;
case 4:
cout << "You added Trail Mix to your cart." << endl;
cost = 1.50;
break;
case 5:
cout << "You added Chocolate to your cart." << endl;
cost = 1;
break;
case 6:
cout << "Checkout" << endl;
break;
default:
cout << "Please select an item from the menu" << endl;
}
cout << "Continue shopping (y/n): " << flush;
string reply;
cin >> reply;
while(reply == "y") {
cout << "Enter your selection: " << flush;
int input;
cin >> input;
float cost;
switch (input) {
case 1:
cout << "You added Popcorn to your cart." << endl;
cost = 2;
break;
case 2:
cout << "You added Coconut Clusters to your cart." << endl;
cost = 3;
break;
case 3:
cout << "You added Granola Bar to your cart." << endl;
cost = 2.50;
break;
case 4:
cout << "You added Trail Mix to your cart." << endl;
cost = 1.50;
break;
case 5:
cout << "You added Chocolate to your cart." << endl;
cost = 1;
break;
case 6:
cout << "Checkout" << endl;
break;
default:
cout << "Please select an item from the menu" << endl;
}
cout << "Continue shopping (y/n): " << flush;
string reply;
cin >> reply;
break;
}
cout << "Proceding to checkout..." << endl;
cout << "Pay amount: $" << flush;
float money;
cin >> money;
if (money > cost) {
float change = money-cost;
cout << "Thank you! You have $" << change << " change." << endl;
}
if (money == cost) {
cout << "Thank you! Have a nice day!." << endl;
}
if (money < cost) {
float amountOwed = cost-money;
cout << "Please insert another $" << amountOwed << endl;
cout << "Enter amount: " << flush;
float payment;
cin >> payment;
if (payment > amountOwed) {
float change2 = payment-cost;
cout << "Thank you! You have $" << change2 << " change." << endl;
}
if (payment == amountOwed) {
cout << "Thank you! Have a nice day!." << endl;
}
if (payment < amountOwed) {
cout << "Sorry, you did not enter enough money. Your cart has emptied." << endl;
}
}
return 0;
}
Edited code:
#include <iostream>
using namespace std;
void vendingMachine() {
cout << "1. Popcorn: $2" << endl;
cout << "2. Coconut Clusters: $3" << endl;
cout << "3. Granola Bar: $2.50" << endl;
cout << "4. Trail Mix: $1.50" << endl;
cout << "5. Chocolate: $1" << endl;
cout << "Press 0 to checkout" << endl;
}
int processSelection() {
cout << "Enter your selection: " << flush;
int input;
cin >> input;
return input;
}
int shoppingCart() {
int selection = processSelection();
float cost;
switch (selection) {
case 1:
cout << "You added Popcorn to your cart." << endl;
cost = 2;
break;
case 2:
cout << "You added Coconut Clusters to your cart." << endl;
cost = 3;
break;
case 3:
cout << "You added Granola Bar to your cart." << endl;
cost = 2.50;
break;
case 4:
cout << "You added Trail Mix to your cart." << endl;
cost = 1.50;
break;
case 5:
cout << "You added Chocolate to your cart." << endl;
cost = 1;
break;
case 6:
cout << "Checkout" << endl;
break;
default:
cout << "Please select an item from the menu" << endl;
}
cout << "Continue shopping (y/n): " << flush;
string reply;
cin >> reply;
return reply;
}
int main() {
cout << "Vending Machine" << endl;
cout << "----Items------" << endl;
vendingMachine();
int reply = shoppingCart();
float cost;
while(reply == "y") {
processSelection();
shoppingCart();
}
cout << "Proceding to checkout..." << endl;
cout << "Pay amount: $" << flush;
float money;
cin >> money;
if (money > cost) {
float change = money-cost;
cout << "Thank you! You have $" << change << " change." << endl;
}
if (money == cost) {
cout << "Thank you! Have a nice day!." << endl;
}
if (money < cost) {
float amountOwed = cost-money;
cout << "Please insert another $" << amountOwed << endl;
cout << "Enter amount: " << flush;
float payment;
cin >> payment;
if (payment > amountOwed) {
float change2 = payment-cost;
cout << "Thank you! You have $" << change2 << " change." << endl;
}
if (payment == amountOwed) {
cout << "Thank you! Have a nice day!." << endl;
}
if (payment < amountOwed) {
cout << "Sorry, you did not enter enough money. Your cart has emptied." << endl;
}
}
return 0;
}
It looks like you're making great progress learning to code. Some thoughts:
Abstract duplicate code. Your switch statement is identical in two places. That makes it easy for bugs to appear! For example, if the price of one item changes, you might forget to update it in one place but not the other, which could lead to tricky bugs.
You have a break statement at the end of the while loop. Do you want to break on every iteration? Probably not. When do you want to break out of the loop? Under what conditions do you not want to continue? Think about the control flow, and how while loops work. While some condition is true, continue looping. Once it's false, stop looping. What is that condition? Is it just reply == y? That works on the first iteration, what about other iterations?
Some of you if statements say things like "have a good day." That sounds like a good time to break out of the loop to me. What do you think?
I have a for loop where when the quantity number is entered, the loop will run for the amount of quantity entered. But unfortunately the output summary only displays one output.
For example, when user enters the quantity number of 2, the loop of choosing the pizza, size and add on runs twice but the summary output in this particular line cout << sizetype << "/t" << pizzatype << "/t" << price << endl; only displays one output. Nevertheless, I want to display both of the output which has been entered by user.
Need help on this.
case 2:
cin >> quantity;
for(int i=0; i<quantity; i++)
cout << "**Pizza Favourites**" << endl;
cout << "1. Italian Aloha" << endl;
cout << "2. Vegi Lover" << endl;
cout << "3. Ocean Delite" << endl << endl;
cout << "Choose Your Pizza (Enter Integer 1-3 Only) : ";
cin >> pizza;
switch (pizza)
{
case 1:
cout << "You've ordered Italian Aloha Pizza" << endl;
pizzatype = "Italian Aloha Pizza";
break;
case 2:
cout << "You've ordered Vegi Lover Pizza" << endl;
pizzatype = "Vegi Lover Pizza";
break;
case 3:
cout << "You've ordered Ocean Delite Pizza" << endl;
pizzatype = "Ocean Delite Pizza";
break;
default:
cout << "Invalid Input" << endl;
break;
}
cout << "**Pizza Sizes**" << endl;
cout << "1. Regular (R)" << endl;
cout << "2. Large (L)" << endl;
cout << "3. X-Large (X)" << endl << endl;
cout << "Choose Your Pizza Size (Enter Integer 1-3 Only) : ";
cin >> size;
switch (size)
{
case 1:
cout << "You've Chose Regular Sized Pizza" << endl;
sizetype = "Regular";
price = newRegular;
break;
case 2:
cout << "You've Chose Large Sized Pizza" << endl;
sizetype = "Large";
price = newLarge;
break;
case 3:
cout << "You've Chose X-Large Sized Pizza" << endl;
sizetype = "X-Large";
price = newXlarge;
break;
default:
cout << "Invalid Input" << endl;
break;
}
}
cout << "**Add On**" << endl;
cout << "Do You Want To Add On Extra Cheese ? (Enter Y for Yes and N for No) : ";
cin >> yesNo;
switch (yesNo)
{
case 'Y':
cout << "More Cheese, More Fun !" << endl;
cheesePrice = newCheese;
break;
case 'N':
cout << "No Extra Cheese Required !" << endl;
cheesePrice;
break;
default:
cout << "Invalid Input" << endl;
break;
}
cout << "WONDER PIZZA" << endl;
cout << "************" << endl;
cout << sizetype << "/t" << pizzatype << "/t" << price << endl;
cout << "Extra Cheese : " << cheesePrice << endl;
total = price + cheesePrice;
cout << "Total Payment : " << total << endl;
cout << "Please Insert Your Payment : " << payment << endl;
change = payment - total;
cout << "Change" << change << endl;
break;
Yes, you can nest a switch statement inside the case of an outer switch statement.
The break on an inner case will be in the context of the inner switch.
(Does that answer your question? I wasn't sure that was your question.)
void Motherboards::add()
{
char x;
int X;
fstream InFileMB("Motherboard_List.txt", ios::in | ios::out | ios::app);
if (!InFileMB)
{
cerr << "Error: Opening File Failed !!";
}
else
{
MotherBoardEntry:
system("cls");
cout << " Enter the name of the Manufacturer :\n";
string MB__Name_Manufacturer;
cin >> MB__Name_Manufacturer;
cout << " Enter Chipset Type :\n";
string MB_Chip;
cin >> MB_Chip;
cout << "Enter Name of the board exactly as it`s written on the box :\n";
string MB_Name;
cin >> MB_Name;
cout << "Enter 3 features of this board :\n";
cout << "1.) ";
string MB_Feature1;
cin >> MB_Feature1;
cout << endl;
cout << "2.) ";
string MB_Feature2;
cin >> MB_Feature2;
cout << endl;
cout << "3.) ";
string MB_Feature3;
cin >> MB_Feature3;
cout << endl;
cout << "Enter Price :\n";
string MB_Price;
cin >> MB_Price;
system("cls");
cout << "Please check the details before conformation :\n";
cout << "Motherboard :\n";
cout << MB__Name_Manufacturer << endl;
cout << MB_Chip << endl;
cout << MB_Name << endl;
cout << "Features :\n";
cout << "1.) " << MB_Feature1 << endl;
cout << "2.) " << MB_Feature2 << endl;
cout << "3.) " << MB_Feature3 << endl;
cout << "Price :\n";
cout << MB_Price;
cout << "\n\n Do You Want To Add The Following Motherboard To Your Stock List ? (y/n)";
cin >> x;
system("cls");
switch (x)
{
case 'y':
InFileMB << "Motherboard :\n" << MB__Name_Manufacturer << endl << MB_Chip << endl << MB_Name << endl << "Price :\n" << MB_Price << endl << "Features :\n" << "1.) " << MB_Feature1 << endl << "2.) " << MB_Feature2 << endl << "3.) " << MB_Feature3 << endl << endl;
break;
case 'Y':
InFileMB << "Motherboard :\n" << MB__Name_Manufacturer << endl << MB_Chip << endl << MB_Name << endl << "Price :\n" << MB_Price << endl << "Features :\n" << "1.) " << MB_Feature1 << endl << "2.) " << MB_Feature2 << endl << "3.) " << MB_Feature3 << endl << endl;
break;
case 'n':
system("cls");
system("pause,2");
cout << " Enter ( 1 ) to try to enter the data again or ( 2 ) to go back to item selection list .. ";
cin >> X;
switch (X)
{
case 1:
goto MotherBoardEntry;
break;
case 2:
break;
}
break;
case 'N':
system("cls");
system("pause,2");
cout << " Enter ( 1 ) to try enter the data again or ( 2 ) to go back to item selection list .. ";
cin >> X;
switch (X)
{
case 1:
goto MotherBoardEntry;
break;
case 2:
break;
}
break;
}
}
}
When I input the data as I am going to show in the snapshots that I provide when I enter the data without any spaces all goes well but when i do enter the data with spaces i cant fill out certain data due to some reason that I don't know as I am a beginner. Can you please tell me exactly where to update and what to update.
[enter image description here][1]
[enter image description here][2]
As you may have noticed in the picture where i have put a space between i7 and 4790k i couldn`t fill out the information for entering the name of the processor and the command window shifted me directly to the next line.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
All of my commands and alters to the array work individually. However, when i try to return to the menu the screen just starts jittering and will not continue. I am forced to close the program. How do i fix this.
/* Programmer: Joshua Zuber
Program Desc: This Program will allow the user to select an icon to display around an array message!
Program Name: Array Demonstration
Clean Compile Date:
*/
#include<iostream>
#include<string>
#include<iomanip>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
// Arrays
string Masterfile[] = "I want to thank all the C++ students who has helped me this semester. You have inspired me to work harder and to be able to design small C++ programs using a gamming approach. ";
string Studentfile[]= "";
// Variables
int Icon;
char again = 'y';
int i;
int j;
int menu = 'y';
int menu2 = 'n';
int menu3 = 'n';
int menu4 = 'n';
int menu5 = 'n';
int objEdit;
while (toupper(again) == 'Y') // Start Main Loop
{
cout << "Welcome to Array Demonstration!" << "\n\n";
cout << Masterfile[0] << "\n\n";
while(toupper(menu) == 'Y' || toupper(menu2) == 'Y' || toupper(menu3) == 'Y' || toupper(menu4) == 'Y' || toupper(menu5) == 'Y' ) // Start Array Menu Loop
{
cout << "Please select one of the below options to edit this string!" << "\n\n";
Studentfile[0] = Masterfile[0];
cout << "1. Size" << "\n\n";
cout << "2. Replace {all of the C++ students} with {My instructer, Professor Penn}" << "\n\n";
cout << "3. Swap the word {small} with {efficient}" << "\n\n";
cout << "4. Erase the phrase {using a gamming approach}" << "\n\n";
cout << "5. View Final Product" << "\n\n";
cin >> objEdit;
if(objEdit == 1) // Menu Array Size Check
{
cout << "The size of the original string is: " << Masterfile[0].size() << "\n\n";
cout << "\n\n" << "Would you like to return to menu? Y/N " << "\n\n";
cin >> menu2 ;
system("cls");
}
else if(objEdit == 2) // Menu 2nd Option
{
cout << "Changing the phrases!" << "\n\n";
Studentfile[0].replace(16,20,"My instructer, Professor Penn");
cout << Studentfile[0] << "\n\n";
cout << "\n\n" << "Would you like to return to menu? Y/N " << "\n\n";
cin >> menu3;
system("cls");
}
else if(objEdit == 3) // Menu 3rd Option
{
cout << "Changing the phrases!" << "\n\n";
Studentfile[0].replace(131,5,"efficient" );
cout << Studentfile[0] << "\n\n";
cout << "\n\n" << "Would you like to return to menu? Y/N " << "\n\n";
cin >> menu4;
system("cls");
}
else if(objEdit == 4) // Menu 3rd Option
{
cout << "Changing the phrases!" << "\n\n";
Studentfile[0].erase(150);
cout << Studentfile[0] << "\n\n";
cout << "\n\n" << "Would you like to return to menu? Y/N " << "\n\n";
cin >> menu5;
system("cls");
}
else if (objEdit <=0 || objEdit >=6) // Menu Failsafe
{
cout << "Please Select a Valid Number" << "\n\n";
cout << "1. Size" << "\n\n";
cout << "2. Replace {all of the C++ students} with {My instructer, Professor Penn}" << "\n\n";
cout << "3. Swap the word {small} with {efficient}" << "\n\n";
cout << "4. Erase the phrase {using a gamming approach}" << "\n\n";
cout << "5. View Final Product" << "\n\n";
cin >> objEdit;
}
else if(objEdit == 5 || toupper(menu) == 'N') // Menu 5th Option
{
cout << "Please Select one of the following numbers to choose a symbol!" << "\n\n";
cout << "1. *" << "\n\n";
cout << "2. ^" << "\n\n";
cout << "3. #" << "\n\n";
cout << "4. +" << "\n\n";
cin >> Icon;
system("cls");
if(Icon <= 0, Icon >= 5) // User Failsafe
{
cout << "You're Entry Is Not Valid" << "\n\n";
cout << "Please Select one of the following numbers to choose a symbol!" << "\n\n";
cout << "1. *" << "\n\n";
cout << "2. ^" << "\n\n";
cout << "3. #" << "\n\n";
cout << "4. +" << "\n\n";
cin >> Icon;
system("cls");
}
else // Icon Breakdown
{
if(Icon == 1) // Icon Choice 1
{
for (i=1;i<=1;i++)
{
for (j=1;j<=i;j++);
{
cout << "*******************************************************************************" << "\n";
cout << Studentfile[0] << "\n";
cout << "*******************************************************************************" << "\n";
cout << endl;
cout << "\n\n" << "Do you wish to play again? Y/N " << "\n\n";
cin >> again;
system("cls");
}
}
}
else if(Icon == 2) // Icon Choice 2
{
for (i=1;i<=1;i++)
{
for (j=1;j<=i;j++);
{
cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << "\n";
cout << Studentfile[0] << "\n";
cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << "\n";
cout << endl;
cout << "\n\n" << "Do you wish to play again? Y/N " << "\n\n";
cin >> again;
system("cls");
}
}
}
else if(Icon == 3) // Icon Choice 3
{
for (i=1;i<=1;i++)
{
for (j=1;j<=i;j++);
{
cout << "###############################################################################" << "\n";
cout << Studentfile[0] << "\n";
cout << "###############################################################################" << "\n";
cout << endl;
cout << "\n\n" << "Do you wish to play again? Y/N " << "\n\n";
cin >> again;
system("cls");
}
}
}
else if(Icon == 4) // Icon Choice 4
{
for (i=1;i<=1;i++)
{
for (j=1;j<=i;j++);
{
cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << "\n";
cout << Studentfile[0] << "\n";
cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << "\n";
cout << endl;
cout << "\n\n" << "Do you wish to play again? Y/N " << "\n\n";
cin >> again;
system("cls");
}
}
}
else // Icon Choice 5
{
cout << "Sorry You Didn't Want to Play" << "\n\n";
cout << "\n\n" << "Do you wish to play again? Y/N " << "\n\n";
cin >> again;
system("cls");
}
}
}
} // End Menu Loop
} // End Main Loop
cout << "Thank you for playing!" << "\n\n";
system("pause");
return 0;
}
Probably because you define menu .. menu5 as int. Try:
char menu = 'y';
char menu2 = 'n';
char menu3 = 'n';
char menu4 = 'n';
char menu5 = 'n';
....
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;
}
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;
}
The problem with the loop is this line:
if(again == 'N' || 'n')
C++ doesn't know that you mean it to check again against both characters. Instead, it tries again == 'N', which fails, and then tries 'n', which - not being zero - evaluates as true.
Instead, try:
if (again == 'N' || again == 'n')
break;