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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!