Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5428
Number of posts: 16943

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
help with project Posted by brody1124 on 5 Jul 2009 at 12:43 PM
Hello everyone. I am writing this because I need some help. I am taking programming I class and I am having problems with this program I wrote and can't figure out how to fix it. I have spent about 2 weeks , off and on, trying to fix it and can't figure it out. The problem is that you cannot enter the title or the isbn to the book. When you loop it, it will not let you enter the date along with the isbn and title.


I attach a copy the program below. Any help will be greatly appreciated.



Report
Re: help with project Posted by AsmGuru62 on 6 Jul 2009 at 4:33 AM
I do not see any attachment.
Report
Re: help with project Posted by brody1124 on 14 Jul 2009 at 7:13 AM
Sorry here is the code. I thought it got attached.

// This program displayes the cashier screen

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

int main()
{
char date[9];
char isbn[25];
char title[25];
char again;
int quantity;
double unitPrice, total, subTotal,tax;
do
{
//Inputs for sales slip
cout << "Please input the date in the format MM/DD/YY.\n";
cin.getline(date,9);
cout << "How many copies of a book is being purchased.\n";
cin >> quantity;
cout << "What is the ISBN number of the book.\n";
cin.getline (isbn,25);
cout << "What is the price of the book.\n";
cin >> unitPrice;
cout << "What is the title of the book.\n";
cin.getline(title,25);
// formula for cashier screen
subTotal = quantity * unitPrice;
tax = 0.06 * subTotal;
total = subTotal + tax;
// Final display Title
cout << "\t\tSerendipity Booksellers\n\n"
<< "Date: " << date <<endl << endl
<< "Qty" << "\tISBN" << "\t\tTitle" << "\t\t\tPrice" << "\t\tTotal\n"
<< "_________________________________________________________________________\n";
// Display inputs
cout << quantity << "\t" << isbn << setw(27) << title <<"\t\t" << unitPrice;
cout << "\t\t" << setprecision(2) << fixed << subTotal << endl << endl << endl;
cout << "\t\t\t Subtotal\t" << setprecision(2) << fixed << subTotal << endl;
cout << "\t\t\t Tax \t" << setprecision(2) << fixed << tax << endl;
cout << "\t\t\t Total \t" << setprecision(2) << fixed << total << endl << endl;

// Thank you line
cout << "Thank you for shopping at Serenipity!\n";

// Does the user have another transaction to be processed
cout << "Do you Have another transaction to be processed? (Y/N)\n";
cin >> again;
} while ( again == 'Y' || again == 'y');
return 0;
}
Report
Re: help with project Posted by toddlerasim on 23 Jul 2009 at 12:38 AM
Just use getchar() at the places indicated and your code should work like a charm.



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

int main()
{
char date[9];
char isbn[25];
char title[25];
char again;
int quantity;
double unitPrice, total, subTotal,tax;
do
{
//Inputs for sales slip
cout << "Please input the date in the format MM/DD/YY.\n";
cin.getline(date,9);
cout << "How many copies of a book is being purchased.\n";
cin >> quantity;
getchar();
cout << "What is the ISBN number of the book.\n";
cin.getline (isbn,25);
cout << "What is the price of the book.\n";
cin >> unitPrice;
getchar();
cout << "What is the title of the book.\n";
cin.getline(title,25);
// formula for cashier screen
subTotal = quantity * unitPrice;
tax = 0.06 * subTotal;
total = subTotal + tax;
// Final display Title
cout << "\t\tSerendipity Booksellers\n\n"
<< "Date: " << date <<endl << endl
<< "Qty" << "\tISBN" << "\t\tTitle" << "\t\t\tPrice" << "\t\tTotal\n"
<< "_________________________________________________________________________\n";
// Display inputs
cout << quantity << "\t" << isbn << setw(27) << title <<"\t\t" << unitPrice;
cout << "\t\t" << setprecision(2) << fixed << subTotal << endl << endl << endl;
cout << "\t\t\t Subtotal\t" << setprecision(2) << fixed << subTotal << endl;
cout << "\t\t\t Tax \t" << setprecision(2) << fixed << tax << endl;
cout << "\t\t\t Total \t" << setprecision(2) << fixed << total << endl << endl;

// Thank you line
cout << "Thank you for shopping at Serenipity!\n";

// Does the user have another transaction to be processed
cout << "Do you Have another transaction to be processed? (Y/N)\n";
cin >> again;
} while ( again == 'Y' || again == 'y');
return 0;
}



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.