Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 21st, 2005, 7:12 PM   #1
Navid
Hobbyist Programmer
 
Navid's Avatar
 
Join Date: Feb 2005
Location: Canada
Posts: 187
Rep Power: 4 Navid is on a distinguished road
Send a message via MSN to Navid
small problem

#include <stdio.h>

float tax = .15;
int price;

int main(void)
{
printf("What is the Cost?");
scanf("%d", &price);

#define total price*tax+price

printf("\nTotal cost= %ld\n",total);
system("pause");
return 0;
}

What it does is it asks for the cost of something, then gives you the cost after adding tax to it. But something is wrong with my variable "tax". Can anyone help please?
Navid is offline   Reply With Quote
Old May 21st, 2005, 7:27 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
I don't think it's a problem with tax. When you make total a variable it works fine. My guess is that there is a different way of defining that, but I don't know how.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old May 21st, 2005, 7:41 PM   #3
nez
Programmer
 
nez's Avatar
 
Join Date: May 2005
Location: Plymouth UK
Posts: 34
Rep Power: 0 nez is on a distinguished road
Send a message via MSN to nez
#include <stdio.h>

flaot tax;
int price; 
float total;

int main()
{
tax=0.15;
printf("What is the Cost?");
scanf("%d", &price);

total=(price*tax)+price;

printf("\nTotal cost = %2.2lf\n",total);

return 0;
}

I think that does the same thing as what u were trying to do but without the define bit, calling total a flaot instead

is this any help?
(i found it useful for me even if it didnt help you)

nez
__________________
atariboy.wordpress.com
nez is offline   Reply With Quote
Old May 21st, 2005, 9:55 PM   #4
Navid
Hobbyist Programmer
 
Navid's Avatar
 
Join Date: Feb 2005
Location: Canada
Posts: 187
Rep Power: 4 Navid is on a distinguished road
Send a message via MSN to Navid
yeah thanks man

but now i have to find out about "%2.2lf"

but this is my first day of C so blah :p
Navid is offline   Reply With Quote
Old May 21st, 2005, 10:15 PM   #5
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
It's just going to print two decimal places with that.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old May 22nd, 2005, 5:12 AM   #6
nez
Programmer
 
nez's Avatar
 
Join Date: May 2005
Location: Plymouth UK
Posts: 34
Rep Power: 0 nez is on a distinguished road
Send a message via MSN to nez
you could have just put "%lf" in but it wil print a number with 4 decimal places, the 2.2 just tames it a bit:

2.2 prints a number with 2 long to 2 decimal places i.e 10.65
4.3 prints a number with 4 long to 3 decimal places i.e 4512.854

hope this helps

nez
__________________
atariboy.wordpress.com
nez is offline   Reply With Quote
Old May 22nd, 2005, 6:54 AM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Basically, tax needs to equal 0.15, not .15.
__________________
Me :: You :: Them

Last edited by Ooble; May 22nd, 2005 at 6:56 AM.
Ooble is offline   Reply With Quote
Old May 22nd, 2005, 7:23 PM   #8
Navid
Hobbyist Programmer
 
Navid's Avatar
 
Join Date: Feb 2005
Location: Canada
Posts: 187
Rep Power: 4 Navid is on a distinguished road
Send a message via MSN to Navid
thanks guys

even though SAMS has a good reputation, i always have questions

this forum shuting down would be a nightmare
Navid is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC