C++ Exercises and Solutions

5.13

(Bar Chart) One interesting application of computers is drawing graphs and bar charts.
Write a program that reads five numbers (each between 1 and 30). Assume that the user enters only valid values. For each number that is read, your program should print a line containing that number
of adjacent asterisks. For example, if your program reads the number 7, it should print *******.


Solution:



 
//C++ Exercises and Solutions
//www.cppexercisesandsolutions.com
//C++ How to Program (8th Edition) By Paul Deitel, Harvey Deitel
//5.13
#include < iostream>
 
using namespace std;
 
int main()
{
  int a, b, c, d, e;
  cout << "Enter five integers (between 1 and 30): ";
  cin >> a >> b >> c >> d >> e;
 
  for( int i = 1; i <= a; i++)
  {
     cout << "*";
   }
   cout << endl;
 
  for( int i = 1; i <= b; i++)
  {
     cout << "*";
   }
   cout << endl;
 
   for( int i = 1; i <= c; i++)
  {
     cout << "*";
   }
   cout << endl;
 
  for( int i = 1; i <= d; i++)
  {
     cout << "*";
   }
   cout << endl;
 
  for( int i = 1; i <= e; i++)
  {
     cout << "*";
   }
   cout << endl;
 
   //for pause
   system("PAUSE");
   return 0;
}
 

Comments  

 
0 #1 Unseen Person 2013-11-02 18:45
Thanks for publishing this solution
Quote
 
 
0 #2 maram ibrahim 2013-11-18 18:46
#include
void main()
{
int num;
cout
Quote
 

Please add your comment if there is any error


Security code
Refresh


Main Menu

Login Form

Latest comments