Question
Problem B: Jukebox Battery Your jukebox has a visual ascii display. You come up with the clever idea of having it display a bar representing
Problem B: Jukebox Battery
Your jukebox has a visual ascii display. You come up with the clever idea of having it display a bar representing how much battery is left. Using the interface to the display, it turns out that you just have to write a void function in C to print out what to display. Your function will take in a percentage and you'll display a bar corresponding to that percentage, with labels on the left-hand side. The function prototype is below. Write your own main to test the function.
// Pre-condition: 0 <= perc <= 100, c is a printable character
// Post-condition: Prints a bar corresponding to perc using the // character c with width 7 and percentage labels
void printBatteryStatus(int perc, char c);
Round perc to the nearest 5% (22% goes to 20% and 43% goes to 45%, for example), and then draw a bar of the character c. Here is what should get printed for perc = 22% and c = '*':
100
95
90
85
80
75
70
65
60
55
50
45
40
35
30
25
20 *******
15 *******
10 *******
5 *******
Battery
battery-scaffold.c
#include#include #include void printBatteryStatus(int perc, char c); int main() { // Get the percentage of battery. int perc; printf("What is the percentage battery you want to display? "); scanf("%d", &perc); // Fix user input. if (perc < 0) perc = 0; if (perc > 100) perc = 100; // Call the function. printBatteryStatus(perc, '*'); return 0; } // Pre-condition: 0 <= perc <= 100, c is a printable character // Post-condition: Prints a bar corresponding to perc using the // character c with width 7 and percentage labels void printBatteryStatus(int perc, char c) { }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started