Arrays problem
Oct 21, 2014 at 4:17pm UTC
Write a C++ Program, ask user to enter 10 interger values. Display its data graphically by plotting each numeric value as a bar of asterisks (*) as shown in the diagram
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<iostream>
using namespace std;
int main()
{
int Ace[10], i;
cout<<" Enter 10 Numbers" <<endl;
cout <<"Element" << "\t\tValue" << "\t\tHistogram" << endl;
for (i=1;i<=10;i++)
{
cout<<i<<"\t\t" ;
cin>>Ace[i];
for (int j=1; j<=Ace[i]; j++)
{
cout<<"x" ;
}
}
}
1 2 3 4 5 6 7
The Output SHOULD be like this :
Elements Values Histogram
1 5 xxxxx
2 10 xxxxxxxxxx
3 6 xxxxxx
and so on, till Element 10 (value = cin<<Ace[i])
but my output shows the histogram on the next line... Please help ,how to show histogram next not the value.
Oct 21, 2014 at 4:26pm UTC
The way you have it now when the user hits enter you are going to get a new line in the console.
Collect the data first. Then print it in another set of loops.
Oct 21, 2014 at 5:07pm UTC
let me try
Last edited on Oct 21, 2014 at 6:01pm UTC
Oct 21, 2014 at 5:54pm UTC
Bit of problem,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int Ace[10], i,j;
cout<<" Enter 10 Numbers" <<endl;
for (i=1;i<=10;i++)
{
cin>>Ace[i];
}
cout <<"Element" << "\t\tValue" << "\t\tHistogram" << endl;
int k;
for (j=1;j<=10;j++)
{
cout<<j<<"\t\t" <<Ace[k]<<"\t\t" <<setfill('x' )<<setw(Ace[i]+1)<<"\n" ;
}
}
The values i enter in the
cin>>Ace[i];
does not print correctly in the value line, help please
Topic archived. No new replies allowed.