Help with "simple for some" c++ output problem..

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 17
Reputation: squigworm is an unknown quantity at this point 
Solved Threads: 0
squigworm squigworm is offline Offline
Newbie Poster

Help with "simple for some" c++ output problem..

 
0
  #1
31 Days Ago
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 ..




  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. int main ()
  7.  
  8. {
  9.  
  10. //Use do to mark the start of the loop and introduce variable needed outside of loop scope.
  11.  
  12. char additional_Transaction ;
  13. do
  14.  
  15. {
  16.  
  17. //Declaring variables
  18.  
  19. char date[10];
  20. int quantity;
  21. char isbn[18];
  22. char title[35];
  23. float price;
  24.  
  25.  
  26.  
  27. //Asks the user to enter p.o.s data
  28.  
  29.  
  30.  
  31.  
  32. cout <<endl << "Please enter todays date in the following format";
  33. cout << " MM/DD/YY: ";
  34. cin >> date;
  35. cout << endl;
  36. cout << "Please enter the quantity of the book being purchased: ";
  37. cin >> quantity;
  38. cout << endl;
  39. cout << "Please enter the books ISBN of the book being purchased: ";
  40. cin >> isbn;
  41. cout << endl;
  42. cin.ignore();
  43. cout << "Please enter the title of the book being purchased: ";
  44. cin.getline (title, 35);
  45. cout << endl;
  46. cout << "Please enter the price of the book being purchased: ";
  47. cin >> price;
  48. cout << endl << endl;
  49.  
  50.  
  51.  
  52.  
  53.  
  54. //Displays information entered by user
  55.  
  56. cout << "Serendipity Booksellers\n Cashier Module" << endl << endl << endl;
  57.  
  58. cout << "Date: " << date << endl ;
  59. cout << "Quantity: " << quantity << endl ;
  60. cout << "ISBN: " << isbn << endl ;
  61. cout << "Title: " << title << endl ;
  62. cout << "Price: $" << price << endl ;
  63.  
  64. //Introducing new variables, and performs calculations
  65.  
  66. float subtotal = price + quantity ;
  67.  
  68. double tax = subtotal * .06 ;
  69.  
  70. float total = subtotal + tax ;
  71.  
  72. //Displays information
  73.  
  74. cout <<endl <<endl << "\t\t\t\t Serendipity Booksellers" <<endl;
  75. cout <<endl <<endl << "Date:" << date <<endl <<endl;
  76. cout << "Qty" << setw(9) << "ISBN" << setw(16) << "Title" << setw(25) <<" Price" << setw(20)<< "Total" <<endl;
  77. cout <<"__________________________________________________________________________________________" <<endl;
  78. cout << quantity << " " ;
  79. cout << setw(15) << left << isbn ;
  80. cout << setw(26) << left << title ;
  81. cout << setprecision(2) << fixed << showpoint << "$" << price ;
  82. cout << setprecision(2) << fixed << showpoint << " $" << left << total ;
  83. cout <<endl <<endl <<endl << setprecision(2) << showpoint << fixed <<" Subtotal $ " << subtotal <<endl;
  84. cout << setprecision(2) << fixed << showpoint <<"\t\t Tax $ " << tax <<endl;
  85. cout << setprecision(2) << fixed << showpoint <<"\t\t Total $ " << total <<endl <<endl;
  86. cout <<endl << "\t Thank You for Shopping at Serendipity!" <<endl <<endl;
  87.  
  88. cout << "\t Would you like to preform another transaction? ";
  89. cin >> additional_Transaction;
  90. cout << endl << endl;
  91.  
  92. //Declare the conditions of the loops repeat execution with while
  93.  
  94. }while ( additional_Transaction == 'Y' || additional_Transaction == 'y' );
  95.  
  96. //Output for program exit
  97.  
  98. cout << "\t Thank You, have a nice day.\n";
  99.  
  100.  
  101.  
  102.  
  103.  
  104. return 0;
  105.  
  106. }


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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,462
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1476
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning
 
-7
  #2
31 Days Ago
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 17
Reputation: squigworm is an unknown quantity at this point 
Solved Threads: 0
squigworm squigworm is offline Offline
Newbie Poster
 
0
  #3
29 Days Ago
Thanks !
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC