need a varaible description
The electricity board charges from their consumers according to the units consumed per month. the amount is calculated as per the tariff.
given below.
UNITS CONSUMED CHARGES
up to 100 units 5.50 unit
for next 200 units 6.50 units
for next 300 units 7.50 units
more than 600 units 8.50 units
consumers name consumers number and the units consumed. the program displays the following information after calculating the amount.
MONEY RECEIPT
consumers number
consumers name
units consumed
amount to be paid
Answers
Answered by
1
#include <stdio.h>
int main(){
char wish;
float num1,num2,result;
int flag =1;
printf(" Enter - , + , * ,/ for knowing result \n");
scanf("%c" , &wish);
printf ("Enter number 1\n");
scanf("%f", &num1 );
printf ("Enter number 2\n");
scanf("%f" , &num2 );
switch (wish)
{
case '+':
result =num1+num2;
break ;
case'-':
result =num1-num2;
break ;
case '/':
{
if (num2 ==0)
{
flag = 0;
}
else
{
result =num1/num2;
}
break ;
}
case'*':
result = num1 *num2;
break ;
default : printf ("error");
break ;
}
if (flag ==1)
{
printf ("%f %c %f =%f" , num1, wish,num2 ,result );
}
else
{
printf ("%f %c %f = undefined" ,num1 ,wish ,num2 );
}
}
Similar questions