Thread: wrote a program; please review/comment

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    4

    wrote a program; please review/comment

    Will this program run?
    Any suggestions?

    Problem: write a c++ program that prompts the user for a cost per item, number of items purchased, and a discount rate. The program should then calculate and print the total cost, tax due, and amount due.

    My program and algorithm:
    //prompt the user for a cost per item
    //prompt the user for number of items purchased
    //prompt the user for a discount rate
    //calculate the total cost, tax due, and amount due.
    //print the total cost, tax due and amount due
    #include <iostream.h>
    int main()
    {
    const float salestax = 0.06;
    float numberitems, costperitem, discountrate, totalcost, taxdue, amountdue, taxrate, newtotal;

    totalcost = numbitems * costperitem;
    newtotal = totalcost - (discountrate * totalcost)
    taxdue = newtotal * taxrate
    amountdue = newtotal + taxdue

    cout<<"enter cost per item";
    cin>> costperitem
    cout<<"enter number of items";
    cin>> numberitems

    cout<<"enter discount rate";
    cin>> discountrate
    cout<< “Your amount due is”<< amountdue
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    Nope, it will not run as you would have expected The flow is incorrect and you forgot some line treminators. Here, I rearranged it for you:
    Code:
    #include <iostream.h> 
    int main() 
    { 
      const float salestax = 0.06; 
      float numberitems, costperitem, discountrate, totalcost;
      float taxdue, amountdue, taxrate, newtotal; 
    
      cout<<"enter cost per item"; 
      cin>> costperitem;
      cout<<"enter number of items"; 
      cin>> numberitems;
      cout<<"enter discount rate"; 
      cin>> discountrate;
    
      totalcost = numbitems * costperitem; 
      newtotal = totalcost - (discountrate * totalcost);
      /*You forgot to compute the taxrate*/;
      taxdue = newtotal * taxrate; 
      amountdue = newtotal + taxdue;
    
      cout<< "Your amount due is"<< amountdue;
      return 0; 
    }
    Last edited by Rez; 05-22-2003 at 07:29 AM.

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Rez, you put a semicolon after your comment about leaving out the calculation of sales tax, and also, don't use <iostream.h>. Use <iostream> and using namespace std;.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    Oops hehe sorry. But even if it has a semicolon, it won't affect the execution anyway.

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    I know, I just thought I'd point it out.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 11:58 PM
  3. Replies: 2
    Last Post: 04-25-2005, 12:59 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM
Website Security Test