pls help me with this code it passes only 66.7% of test cases | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
0

# pls help me with this code it passes only 66.7% of test cases

An electricity board charges the following rates to domestic users: If the number of units consumed is less than or equal to 100, then cost per unit is Rs.1.00 If the number of units consumed is greater than 100 and less than or equal to 300, then cost per unit is Rs.2.00 If the number of units consumed is greater than 300 units, then cost per unit is Rs.3.00 All users are charged a minimum of Rs. 50.00. If the total amount is more than Rs.1000, then an additional surcharge of 15% is added. Write a C program to read the user id, name and number of units consumed by an user and prints the user id, name and charges. #include<stdio.h> int main() { int id,unt,x; float v; printf("Enter the user id of user\n"); scanf("%d",&id); char str[20]; printf("Enter the name of user\n"); scanf(" %[^\n]%*c", str); printf("Enter the number of units consumed by user"); scanf("%d",&unt); if(unt==0) { x=50; } else if(unt<=100) { x=unt*1; } else if(unt>100&&unt<=300) { x=unt*2; } else { x=unt*3; } if(x>1000) { x+=((15*x)/100); } else{ } v=(float)x; printf("\nCharge details\n"); printf("%d",id); printf(" %s",str); printf(" %.2f",v); return 0; }

27th Dec 2020, 3:38 PM
yogesh
2 Respostas
+ 7
yogesh Patiently read the Question couple of times and you'll understand . This challenges are made to test the users knowledge and understanding on the concept ... If you want help with the codes , Post your attempt to get help from the community...
27th Dec 2020, 3:49 PM
Alphin K Sajan
0
#include<stdio.h> int main() { int id,unt,x; float v; printf("Enter the user id of user\n"); scanf("%d",&id); char str[20]; printf("Enter the name of user\n"); scanf(" %[^\n]%*c", str); printf("Enter the number of units consumed by user"); scanf("%d",&unt); if(unt==0) { x=50; } else if(unt<=100) { x=unt*1; } else if(unt>100&&unt<=300) { x=unt*2; } else { x=unt*3; } if(x>1000) { x+=((15*x)/100); } else{ } v=(float)x; printf("\nCharge details\n"); printf("%d",id); printf(" %s",str); printf(" %.2f",v); return 0; }
27th Dec 2020, 4:30 PM
yogesh