[QUOTE=Bnchs400]Actually, today my professor gave us a new assignment to do the same thing, this time using a single for loop in a function.
When the program is run, I have to enter two numbers and only the second number gets the "*" output. Does anyone have a suggestion on how to fix this?
Code:
#include <iostream.h>
#include <stdlib.h>
void bargraph(int number)
{
int x;
cin >>x;
{for( ; x>0; x--)
cout <<"*";
}
}
int main()
{
int a;
cin>> a;
bargraph (a);
system("PAUSE");
return 0;
}
The last assignment for this program is to modify this code. The new program should use a function, for loop, and an array of maximum size 20. The user defines how many numbers are input and the output should be each number that was input. For example:
If the user defines 3 numbers and enters an input of 3, 4, 5 the output should be:
***
****
*****
I have made progress but still am not receiving the right output.
Code:
#include <iostream.h>
#include <stdlib.h>
void bargraph(int number)
{
for( int i=0; i <number; i++)
cout <<"*";
cout <<endl;
}
int main()
{
int bar[20];
int number;
cout << "How many Numbers to Print Stars For? ";
cin >> number;
for(int i = 0; i < number; i++)
{
cout << "Enter a Number: ";
cin >> bar[i];
}
bargraph(number);
system("PAUSE");
return 0;
}
Any suggestions would be greatly appreciated. Thanks.