How to calculate and display electricity used in a month using fprintf?
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Spaceman
le 23 Fév 2024
Modifié(e) : Spaceman
le 8 Avr 2024 à 3:59
Given: A power company charges 6.6 cents per KWH of electricity.
Find: Write a script that prompts the user for the number of KWH's they used in a month. The script should then calculate the total elecericty charge for the month and display it in dollars, with 2 decimals.
...
I got it figured out :
n = input('How many kWh this month: ');
fprintf('Your charge for 200 kWh will be $%.2f\n', 0.066*n);
0 commentaires
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 23 Fév 2024
KWH = input('How many KWH this month: ');
BILL = 0.066 * KWH;
fprintf('Your charge for %f KWH will be $%.2f\n', KWH, BILL)
Voir également
Catégories
En savoir plus sur Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!