求诸位帮忙看看错在哪里。

求各位帮忙看看错在哪里。。。编写一个程序,根据从键盘输入一个数值,计算总价(单价是¥5)。数值超过30的折扣是1

求各位帮忙看看错在哪里。。。
编写一个程序,根据从键盘输入一个数值,计算总价(单价是¥5)。数值超过30的折扣是10%,数值超过50的折扣是15%。

/* Program 3.3 */
#include "stdio.h"
int main (void)
{
  const int price = 5;
  int quantity =0;
  double total_price =0.0;
   
  printf("Enter the quantity you want to buy : ");
  scanf("%d",&quantity);
  
  if(quantity<=30&&quantity>=1)
  printf("The total_price is $%.2lf.",total_price);
  total_price= price*quantity*1;
  
  if(quantity>30&&quantity<=50)
  printf("The total_price is $%.2lf.",total_price);
  total_price= price*quantity*(1-0.01);
  
  if(quantity>50)
  printf("The total_price is $%.2lf.",total_price);
  total_price= price*quantity*(1-0.15);
  
  return 0;
}



[解决办法]
你先输出再赋值,在输出的时候输出的其实还是你定义的初值,当然是0了。
把printf语句和赋值语句换一下就好了,当然加上括号最好了。代码如下:

#include "stdio.h"
int main (void)
{
const int price = 5;
int quantity =0;
double total_price =0.0;

printf("Enter the quantity you want to buy : ");
scanf("%d",&quantity);

if(quantity<=30&&quantity>=1)
{
total_price= price*quantity*1;
printf("The total_price is $%.2lf.",total_price);
}

if(quantity>30&&quantity<=50)
{
total_price= price*quantity*(1-0.01);
printf("The total_price is $%.2lf.",total_price);
}

if(quantity>50)
{
total_price= price*quantity*(1-0.15);
printf("The total_price is $%.2lf.",total_price);
}
return 0;
}