6 Replies - 1447 Views - Last Post: 20 April 2006 - 09:00 AM Rate Topic: -----

#1 Fux39  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-April 06

Small Problem... Please Help!

Posted 19 April 2006 - 08:57 PM

I know by looking at this there is a bunch of errors... But I need to worry more about the red parts right now... I am trying to figure out how to make a void function that prompts the user for a number of items "purchased" and then reads from the keyboard that number... After that I can figure out how to set up how to get the items to add up to a total so I can work with that total number... Please help!!!

#include <iostream>
#include <iomanip>
#include <fstream>

void number_items();
double shipping_chrg(double, int);
double calc_discount_price(double, double);
double calc_tax(double, double);
double calc_amount_due(double, double);

using namespace std;

int main()
{
void number_items();
discount_price = calc_discount_price(price, DISCOUNT_PERCENT);
tax = calc_tax(discount_price, TAX_RATE);
SHIP_CHRG = shipping_chrg(price, FREE_SHIPCUT);
price_b4_ship = discount_price + tax;
total_due = calc_amount_due(price_b4_ship, SHIP_CHRG);
}

void number_items()
{
cout << "Please enter the number of items purchased: ";
cin >> number_oitems;

for(i = number_oitems; i >= 0; i--)
{
cout << "Enter the item price: $";
cin >> item_price;

items_total =
}

/*
Function: shipping_chrg

The function shipping_chrg is a typed function that determines whether there
is a shipping charge.

Receives: price and FREE_SHIPCUT
Constants: FREE_SHIPCUT
Returns: SHIP_CHRG (double)
*/

double shipping_chrg(double price, int FREE_SHIPCUT)
{
double SHIP_CHRG;

if(price >= FREE_SHIPCUT)
{
SHIP_CHRG = 0.00;
}
else
{
SHIP_CHRG = 8.50;
}

return SHIP_CHRG;
}


/*
Function: calc_discount_price

The function calc_discount_price is used to calculate the price with a
discount of 25%.

Receives: price and DISCOUNT_PERCENT
Constants: DISCOUNT_PERCENT
Returns: discount_price
*/

double calc_discount_price(double price, double DISCOUNT_PERCENT)
{
double discount_price;

discount_price = price - (price * DISCOUNT_PERCENT);

return discount_price;
}


/*
Function: calc_tax

The function calc_tax is used to determine how much the tax will be by using
discount_price and TAX_RATE (doubles).

Receives: disount_price and TAX_RATE
Constants: TAX_RATE
Returns: tax
*/

double calc_tax(double discount_price, double TAX_RATE)
{
double tax;

tax = discount_price * TAX_RATE;

return tax;
}


/*
Function: calc_amount_due

The function calc_amount_due is used to calculate the total amount due by
price_b4_ship and SHIP_CHRG.

Receives: price_b4_ship and SHIP_CHRG
Constants: SHIP_CHRG
Returns: total_due
*/

double calc_amount_due(double price_b4_ship, double SHIP_CHRG)
{
double total_due;

total_due = price_b4_ship + SHIP_CHRG;

return total_due;
}

Is This A Good Question/Topic? 0
  • +

Replies To: Small Problem... Please Help!

#2 wingz198  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 14-October 05

Re: Small Problem... Please Help!

Posted 19 April 2006 - 10:02 PM

How come you need a void function? If you're calling the totaling function in main, you can't get what the user entered.
Was This Post Helpful? 0
  • +
  • -

#3 frog  Icon User is offline

  • unleashed
  • member icon

Reputation: 2
  • View blog
  • Posts: 683
  • Joined: 26-March 06

Re: Small Problem... Please Help!

Posted 20 April 2006 - 05:26 AM

okay your code is a complete mess.u tried to bring abt modularity in your program ,thats good.but u havent declared any variable.you havent initialized anything.ur not giving any outputs for the result. in all ur algorithm is correct but u need to take of the syntax

here's the corrected code.i've added comments.



#include <iostream>
#include <iomanip>
#include <fstream>

void number_items();
double shipping_chrg(double, int);
double calc_discount_price(double, double);
double calc_tax(double, double);
double calc_amount_due(double, double);

using namespace std;

int main()
{
void number_items();//this is not the function call.its a redeclaration of the prototype.the call would be number_items()
 
//nothing is declared or intialized in this part 
discount_price = calc_discount_price(price, DISCOUNT_PERCENT);
tax = calc_tax(discount_price, TAX_RATE);
SHIP_CHRG = shipping_chrg(price, FREE_SHIPCUT);
price_b4_ship = discount_price + tax;
total_due = calc_amount_due(price_b4_ship, SHIP_CHRG);
}

void number_items()
{
cout << "Please enter the number of items purchased: ";
cin >> number_oitems;//declare it as int

for(i = number_oitems; i >= 0; i--)//i is not declared
{
cout << "Enter the item price: $";
cin >> item_price;// not declared
/*heres the code:
double item_total=0;
item_total+=item_price;
*/ 
items_total = 
} 
/*
Function: shipping_chrg

The function shipping_chrg is a typed function that determines whether there
is a shipping charge.

Receives: price and FREE_SHIPCUT
Constants: FREE_SHIPCUT
Returns: SHIP_CHRG (double)
*/ 

double shipping_chrg(double price, int FREE_SHIPCUT)
{
double SHIP_CHRG;

if(price >= FREE_SHIPCUT)
{
SHIP_CHRG = 0.00;
}
else
{
SHIP_CHRG = 8.50;
}

return SHIP_CHRG;
} 


/*
Function: calc_discount_price

The function calc_discount_price is used to calculate the price with a 
discount of 25%.

Receives: price and DISCOUNT_PERCENT
Constants: DISCOUNT_PERCENT
Returns: discount_price
*/

double calc_discount_price(double price, double DISCOUNT_PERCENT)
{
double discount_price;

discount_price = price - (price * DISCOUNT_PERCENT);

return discount_price;
}


/*
Function: calc_tax

The function calc_tax is used to determine how much the tax will be by using
discount_price and TAX_RATE (doubles).

Receives: disount_price and TAX_RATE
Constants: TAX_RATE
Returns: tax
*/ 

double calc_tax(double discount_price, double TAX_RATE)
{
double tax;

tax = discount_price * TAX_RATE;

return tax;
} 


/*
Function: calc_amount_due

The function calc_amount_due is used to calculate the total amount due by 
price_b4_ship and SHIP_CHRG.

Receives: price_b4_ship and SHIP_CHRG
Constants: SHIP_CHRG
Returns: total_due
*/

double calc_amount_due(double price_b4_ship, double SHIP_CHRG)
{
double total_due;

total_due = price_b4_ship + SHIP_CHRG;

return total_due;
} 


Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Small Problem... Please Help!

Posted 20 April 2006 - 06:10 AM

wingz198, on 19 Apr, 2006 - 10:54 PM, said:

How come you need a void function? If you're calling the totaling function in main, you can't get what the user entered.

A variable can be passed to the function by reference to capture the total.

and Frog, thank you very much for helping out, but please remember that we prefer to guide users when it comes to academic assignments, as opposed to simply providing them with complete code.
Was This Post Helpful? 0
  • +
  • -

#5 frog  Icon User is offline

  • unleashed
  • member icon

Reputation: 2
  • View blog
  • Posts: 683
  • Joined: 26-March 06

Re: Small Problem... Please Help!

Posted 20 April 2006 - 06:47 AM

if u see ive added comments to the code and not changed it . i thought it would help him out better
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Small Problem... Please Help!

Posted 20 April 2006 - 07:29 AM

Whoops! My mistake...please accept my apologies...I should have paid more attention! :)
Was This Post Helpful? 0
  • +
  • -

#7 frog  Icon User is offline

  • unleashed
  • member icon

Reputation: 2
  • View blog
  • Posts: 683
  • Joined: 26-March 06

Re: Small Problem... Please Help!

Posted 20 April 2006 - 09:00 AM

its quite fine happens.no probs :)

This post has been edited by frog: 20 April 2006 - 09:01 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1