Hello,

I am having trouble with one of my assignments and was hoping someone could help explain why this problem is occurring.

The following code is set up to ask the user if they would like another transaction after they have completed the program. The first time the user inputs data the output stays in its proper format, but if the user elects to perform another transaction the table in the output is manipulated..

Here is the code and below it is a description of the problematic output ...

Help would be greatly appreciated and any advice on how I have written the code or about anything is greatly appreciated ..

#include <iostream> 
#include <iomanip>
#include <cstring>
using namespace std;

int main ()

{

    //Use do to mark the start of the loop and introduce variable needed outside of loop scope.

    char additional_Transaction ;
    do
	
	{

    //Declaring variables

	char date[10];
    int quantity;
	char isbn[18];
	char title[35];
	float price;
    
	
	
	//Asks the user to enter p.o.s data


    

	cout <<endl << "Please enter todays date in the following format";
	cout << " MM/DD/YY: ";
	cin >> date; 
	cout << endl;
	cout << "Please enter the quantity of the book being purchased: ";
	cin >> quantity;
	cout << endl;
	cout << "Please enter the books ISBN of the book being purchased: ";
	cin >> isbn;
	cout << endl;
	cin.ignore();
	cout << "Please enter the title of the book being purchased: ";
	cin.getline (title, 35);
	cout << endl;
	cout << "Please enter the price of the book being purchased: ";
	cin >> price;
	cout << endl << endl;





    //Displays information entered by user 

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

	cout << "Date: " << date << endl ;
	cout << "Quantity: " << quantity << endl ;
	cout << "ISBN: " << isbn << endl ;
	cout << "Title: " << title << endl ; 
	cout << "Price: $" << price << endl ; 

    //Introducing new variables, and performs calculations

	float subtotal = price + quantity ;
	
	double tax = subtotal * .06 ;
	
	float total = subtotal + tax ;

    //Displays information 
	
	cout <<endl <<endl << "\t\t\t\t                     Serendipity Booksellers" <<endl; 
	cout <<endl <<endl << "Date:" << date <<endl <<endl;
	cout << "Qty" << setw(9) << "ISBN" << setw(16) << "Title" << setw(25) <<"    Price" << setw(20)<< "Total" <<endl;
	cout <<"__________________________________________________________________________________________" <<endl;
	cout << quantity << "      " ;
	cout << setw(15) << left << isbn ;
	cout << setw(26) << left << title ;
	cout << setprecision(2) << fixed << showpoint << "$" << price ;
	cout << setprecision(2) << fixed << showpoint << "              $" << left << total ;
	cout <<endl <<endl <<endl << setprecision(2) << showpoint << fixed <<"           Subtotal           $ " << subtotal <<endl;
	cout << setprecision(2) << fixed << showpoint <<"\t\t   Tax                $ " << tax <<endl;
	cout << setprecision(2) << fixed << showpoint <<"\t\t   Total              $ " << total <<endl <<endl;
	cout <<endl << "\t       Thank You for Shopping at Serendipity!" <<endl <<endl;
	
	cout << "\t       Would you like to preform another transaction? ";
	cin >> additional_Transaction;
	cout << endl << endl; 
	
	//Declare the conditions of the loops repeat execution with while 

	}while ( additional_Transaction == 'Y' || additional_Transaction == 'y' );
	 
	//Output for program exit  
	 
	cout << "\t       Thank You, have a nice day.\n";
	

	


    return 0;

}

In the first iteration The table headings(Qty,ISBN,Title,Price,Total) are spaced properly

In any additional iteration the table headings scrunch up to the left ...

Can someone please help.

Thanks !

Colin

Recommended Answers

All 2 Replies

You should not be using tabs but setw() method. Tabs may display differently on different computers/monitors. I think setw() will give you a consistent appearance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.