Barra de vida
#include <stdio.h> #include <stdlib.h> #include <string.h> void life_bar(int life, int max_life) { int full_life; full_life = (int) (20 * life/max_life); int i; if (full_life == 0) printf("[-"); else { printf("["); for (i = 0; i < full_life; i++) printf("="); printf("-"); } for (i = 0; i < 19 - full_life; i++) printf(" "); printf("]\n"); return; } int main() { int max_life; int life; for (life = 0; life <= max_life; life++) { printf("%d", life); life_bar(life, max_life); } return 0; }