Thread: DID I DO THIS RIGHT ...i tried to run it ... it doesn't work....

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    22

    Post DID I DO THIS RIGHT ...i tried to run it ... it doesn't work....

    i have been tryin' to run it... but it still doesn't work

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Please post you code in code tags. Don't attach it.

    Your problem is the cin of the string. You should use getline();

    Code:
    cin.getline(custname,50,'\n');
    Though after the cin before it, you need to take the '\n' out of the buffer with this:

    Code:
    cin.ignore();
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    22
    wait so....where i am goin to put itcout << "Enter the day: ";
    cin >> day;

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Well... you could put it after every cin statement, but that's unnessasary because the extraction operator ( >> ) ignores leading whitespace. getline() doesn't. So you really only need this:

    Code:
    cout << "Enter the year: ";
    cin >> year;
    cin.ignore();   // Take the newline
    
    cout << "Please enter your full name: ";
    cin.getline(cust_name,50,'\n');    // Read in a full string up to the newline
    Sent from my iPadŽ

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    22
    thank you

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    22
    how do you u make da date on da output like this 02/25/06
    and also when i run it ...after I enter the number of reprints ordered..the run program automically closed....thanks again...

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Here is the whole program, for reference:
    Code:
    /*
    Name: Jamilton 
    Copyright:
    Author:
    Date:
    Description:
    */
    //************************Preprocessor Directives*********************
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <iomanip>
    //*****************************Main******************************
    using namespace std;
    const double SALES_TAX = 0.06; //declaration of constant value
    const double REPRINTS = 0.50;
     
    int main ()
    {
    char cust_name[50]; //customer first and last name
    char dummy;
    double total_reprints;
    double tax_amount;
    double reprint_cost;
    double total_cost;
    int photos_submitted;
    int reprints_ordered;
    int month;
    int day;
    int year;
     
    // input section
    cout << "Enter the month: ";
    cin >> month;
     
    cout << "Enter the day: ";
    cin >> day;
     
    cout << "Enter the year: ";
    cin >> year;
     
    cout << "Please enter your full name: ";
    cin >> cust_name;
     
    cout << "Enter the number of photos submitted: ";
    cin >> photos_submitted;
     
    cout << "Enter the number of reprints ordered: ";
    cin >> reprints_ordered;
     
    //compute total reprints
    total_reprints = photos_submitted * reprints_ordered;
    // compute reprint cost
    reprint_cost = total_reprints * REPRINTS;
    // compute tax
    tax_amount = reprint_cost * SALES_TAX;
    // compute total cost
    total_cost = reprint_cost + tax_amount;
     
    // output section
     
    cout << "MOREPRINTS PHOTO STORE" << endl <<endl;
    cout << "______________________" << endl <<endl;
    cout << "Date: " << month << "/" << day << "/" << year << endl;
    cout << "Customer Name: " << cust_name << endl;
    cout << "Photos In: " << photos_submitted << endl;
    cout << "Reprints Ordered: " << reprints_ordered << endl << endl << endl;
    cout << setiosflags(ios::fixed) << setprecision(2);
    cout << "Total Reprints: " << total_reprints << endl;
    cout << "Price/Reprint: " << REPRINTS << endl;
    cout << "Reprint Cost: " << reprint_cost << endl;
    cout << "Tax: " << tax_amount << endl;
    cout << "Total Cost: " << total_cost << endl << endl;
     
    cout << "Press any key to continue." << endl;
    
     
    return 0;
    }
    how do you u make da date on da output like this 02/25/06
    Try <iomanip>. setw().
    and also when i run it ...after I enter the number of reprints ordered..the run program automically closed....thanks again...
    You want to keep the window open so you can see its output? http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    22
    where i am gonna put dis code <iomanip>. setw().

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Okay:
    Code:
    #include <iomanip>
    
    cout << setw(2) << day << '/' << setw(2) << month << '/' << setw(2) << year << endl;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Feb 2006
    Posts
    22
    PROBLEM SPECIFICATION

    The MOREPRINTS Photo Store needs a program to calculate a customer bill based on the number
    of photos submitted and the number of reprints ordered. Reprints cost fifty cents a piece. The number
    of reprints ordered will be the same for each photo submitted: example - 5 photos, 3 reprints would be
    15 total reprints. Sales tax is 6%. The customer bill should include the customer's name ( first and last).
    The number of photos submitted, the number of reprints ordered, total number of reprints made, the cost
    per reprint, the total cost of reprints, tax, and total bill.

    Input: Customer Name
    Order Date (MM//DD/YY)
    Number of Photos submitted
    Number of reprints ordered

    CONSTANT: Any Information that is given and that will not be changed by the entry of data or by
    calculation.

    Variables: Data that will be changed by data entry, data calculation, or data manipulation.

    Calculations: Number of photos * number of reprints
    Total reprints * cost per reprint,
    Cost of reprints * tax percentag e
    Cost of reprints + tax amount

    Output: ALL inputs and calculated data.

    well....is dat correct.....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How properly inherit from template?
    By 6tr6tr in forum C++ Programming
    Replies: 118
    Last Post: 04-25-2008, 04:30 AM
  2. My monitor doesn't work with Ubuntu Linux.
    By indigo0086 in forum Tech Board
    Replies: 1
    Last Post: 07-12-2007, 10:59 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. If you are employed as a programmer, please look
    By Flood Fighter in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 09-28-2004, 02:35 AM
  5. Wont run in X, works fine in alt+F1 terminal
    By zmerlinz in forum Linux Programming
    Replies: 5
    Last Post: 04-28-2004, 11:58 AM