0

I am having trouble taking a histogram program I made in class and making it interactive where the numbers are inputted by the user.
Any help would be greatly appreciated.

#include "stdafx.h"
#define SIZE 10

int main()
{
	int n[ SIZE ]= {19, 3, 15, 7, 11, 9, 13, 5, 17, 1};
	int i;
	int j;

	printf( "%s%13s%17s\n", "Element", "Value", "Histogram" );

	for ( i = 0; i < SIZE; i++) {
		printf( "%7d%13d       ", 1, n[ i ]);

		for ( j = 1; j <= n[ i ]; j++) {
			printf("%c", '+' );
		}

		printf("\n");

	}


	return 0;
}
2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by gerard4143
0

Well first I would get the working functionality out of the way....I would create a function that displays your array.

#include <stdio.h>
#define SIZE 10

void myfunc(int *x)
{
	int i;
	int j;

	printf( "%s%13s%17s\n", "Element", "Value", "Histogram" );

	for ( i = 0; i < SIZE; i++) {
		printf( "%7d%13d       ", i, x[ i ]);

		for ( j = 1; j <= x[ i ]; j++) {
			printf("%c", '+' );
		}

		printf("\n");

	}
}

int main()
{
	int n[ SIZE ]= {19, 3, 15, 7, 11, 9, 13, 5, 17, 1};

	/*If you want...prompt user for values here in a for loop*/

	myfunc(n);

	return 0;
}

Edited by gerard4143: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.