loops - How too create a bar chart in c++ without functions or arrays -


i've spent past 5 hours trying write program, got halfway , realised cant use arrays or functions, strings etc.

the problem need create program reads integer values terminated sentinel value , displays bar chart of single digit numbers(0-9). chart shows total number of occurrences each number in sequence. here have far

edit: revised code

#include <iostream> using namespace std;  int main() {    //initilise variables     int num = 0, count0 = 0, count1 = 0,count2 = 0,count3 = 0,count4 = 0,  count5 =0, count6 = 0,count7 = 0,count8 = 0,count9 = 0, value; int sentinel = -1;  //get numbers till -1 values has been entered cout << "please enter number: "; while(num != sentinel) {     cin >> num;      //adds each occurrence of number entered     switch(num) {     case 0:         count0+= 1;         break;     case 1:         count1+= 1;         break;     case 2:          count2+=1;         break;     case 3:         count3+= 1;         break;     case 4:         count4+= 1;         break;     case 5:          count5+= 1;         break;     case 6:         count6+= 1;         break;     case 7:         count7+= 1;         break;     case 8:          count8+= 1;         break;     case 9:         count9+= 1;         break;     default:; } }  for(int rows = 0; rows < 10; rows++) {     cout << endl << rows << " | ";     for(int c = 0; c < count0; c++)     {         {             cout << "*" ;          }     }  } 

edit:

im having trouble getting loop columns output * on single row. idea should change allow that? far, if input 3 zero's(count0=3) display 3 "*", on 9 rows.

if need count single digit numbers, 1 way go use 10 variables =) int count0, count1... etc... have array so, can count input , output counted values..


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -