C++ examples for Statement:while
Print bar chart of entered values
#include <iostream> void printLine(int); int main(int argc, const char *argv[]) { int counter = 5; int value = 0; while (counter > 0) { printf("Enter an integer value 1-30 (%d remaining): ", counter); std::cin >> value;//from ww w . j av a 2 s .co m if (value >= 1 && value <= 30) { printLine(value); counter--; } else { std::cout << "Incorrect value entered." << std::endl; } } return 0; } void printLine(int value) { for (int i = 0; i < value; i++) { std::cout << "*"; } std::cout << std::endl; }