never to old

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 3
Reputation: old lady is an unknown quantity at this point 
Solved Threads: 0
old lady old lady is offline Offline
Newbie Poster

never to old

 
-1
  #1
Nov 10th, 2004
I'm told you are never to old to learn something new but right now I don't believe that. I thought I understood this but the program I wrote just doesn't work any suggestions?


Write a program that asks the user to enter the price of an item and the sales tax rate as a percent. The program should display th total price of the item (price plus sales tax) After obtaining the input from the user, the program should use the *= operator to calculate the total price of the item using the equivalent of the following formula
price=price*( 1 +sales_tax_rate)


//This program calculates Total price of the item (price+sales tax).

#include <iostream.h>
#include<iomanip.h>


//using namespace std;
int main()

{
const price*=sales_tax_rate,
price of item,
sales_tax,
total;
//Display price of item
cout<<"\n Enter the price of the item;
cin>> item_price

//calculate tax
sales_tax=item price*sales_tax_rate;
total= item_price + sales_tax;

//Display price and total
cout<<"\n price of item" <<item_price;
cout<<"\nsales tax" <<sales_tax;
cout<<"\n total amount<<total;

return 0;

}
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 185
Reputation: Stack Overflow is an unknown quantity at this point 
Solved Threads: 4
Stack Overflow's Avatar
Stack Overflow Stack Overflow is offline Offline
C Programmer

Re: never to old

 
0
  #2
Nov 10th, 2004
Greetings,

There are a few syntatical errors in your program. Let's walk through them one step at a time.

Point A
First issue is the local variables themselves. Nothing major, it can be fixed. Let's look at what we have:
const price*=sales_tax_rate,
price of item,
sales_tax,
total;
Alright, this may cause a few errors if not a ton. I see you declared price as a constant variable that equals sales_tax_rate, though there is no trace of such a variable here. Of course you are initializing a constant variable for the rest without a data type. Since prices and percentages work with decimals alot, lets make these variables floating-type variables:
int main() {
	float item_price, sales_tax, total;
	float sales_tax_rate = .081f;
All four variables are floats. The last variable, sales_tax_rate is 8.1% in decimal style, or 0.81. The f is there to tell the compiler this is a float not a double. That is on an enitrely different topic, so lets move to the next step.

Point B
Secondly we need to input from the user to store in our float item_price. This is easy:
	//Display price of item
	cout << "Enter the price of the item: ";
	cin >> item_price;
As you may see we used cout and cin. Each ending with a semi-colon to break that lines worth of code. Without that semi-colon, the next line may whine about how a computation that started never ended.

Point C
Here we calculate our tax by multiplying the items price by the tax rate we set as 0.81.
	//calculate tax
	sales_tax = item_price * sales_tax_rate;
	total = item_price + sales_tax;
This is quite simple. The equation is set to sales_tax, and the total adds it to the price, etc...

Of course we just display it now:
	//Display price and total
	cout << "\nprice of item: " << item_price;
	cout << "\nsales tax: " << sales_tax;
	cout << "\ntotal amount: " << total;

	return 0;
}
If you have further questions, please feel free to ask.


- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.

IRC
Channel: irc.daniweb.com
Room: #c, #shell
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 48
Reputation: Coach_Nate is an unknown quantity at this point 
Solved Threads: 0
Coach_Nate's Avatar
Coach_Nate Coach_Nate is offline Offline
Light Poster

Re: never to old

 
0
  #3
Nov 11th, 2004
not to mention that your "using namespace std;" at the top is commented out. Also, relating to stack's comment on syntax, there are a few lines with commas at the end rather than semicolons.

happy coding & don't give up!
And remember, your head stops hurting after you stop beating it off the wall.
ok, seriously, anything worth doing was ever learned overnight.
Last edited by Coach_Nate; Nov 11th, 2004 at 12:43 am. Reason: noticed more stuff
Behind every great gymnast - is a mentally unstable coach.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 1569 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC