![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
|
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? |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
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.
__________________
"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." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Programmer
|
#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 |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
yeah thanks man
but now i have to find out about "%2.2lf" but this is my first day of C so blah :p |
|
|
|
|
|
#5 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
It's just going to print two decimal places with that.
__________________
"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." - Dwight D. Eisenhower |
|
|
|
|
|
#6 |
|
Programmer
|
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 |
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Basically, tax needs to equal 0.15, not .15.
Last edited by Ooble; May 22nd, 2005 at 6:56 AM. |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
|
thanks guys
even though SAMS has a good reputation, i always have questions this forum shuting down would be a nightmare |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|