Thread: Chart!

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    36

    Chart!

    I'm making a program that lets the user enter a bunch of info, like student grades for example... then the program will produce a chart using the entered data.


    Chart should look like this:

    Number of
    Students
    10 |
    9 |
    8 |
    7 |
    6 |
    5 |
    4 | *
    3 |
    2 | *
    1 | * * *
    0 | *
    -----------------------------------------------------------
    0 1 2 3 4 5 6 7 8 9 10

    Whats the best way of getting the *'s in the chart??
    Last edited by 98dodgeneondohc; 04-21-2005 at 11:12 AM.

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Good to know. Did you have a question, or was your intent to simply inform us of your programming adventures?

    [edit]
    Quote Originally Posted by 98dodgeneondohc
    Whats the best way of getting the *'s in the chart??
    printf with a for loop?
    Last edited by pianorain; 04-21-2005 at 11:16 AM.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    36
    Quote Originally Posted by pianorain
    Good to know. Did you have a question, or was your intent to simply inform us of your programming adventures?
    lol! sorry man.. I accidentally pressed enter half way through the post before posting the question.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Whats the best way of getting the *'s in the chart??
    Code:
    putchar( '*' );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by 98dodgeneondohc
    lol! sorry man.. I accidentally pressed enter half way through the post before posting the question.
    Heh...aye. It would help if you posted some code demonstrating your attempt. Otherwise, we can't really help.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I see the Y axis is the number of students, but what's the X axis of the chart?
    If you understand what you're doing, you're not learning anything.

  7. #7
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    Quote Originally Posted by itsme86
    I see the Y axis is the number of students, but what's the X axis of the chart?
    The grades probably going from 0 to 10 .

  8. #8
    Registered User
    Join Date
    Apr 2005
    Posts
    36
    how will it know where to put the *'s based on what the user enters??? .... X is number of students and Y is marks by the way

  9. #9
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    There is a post regarding your question on the board as well. A quick search should help you out on how to get started.
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  10. #10
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by GanglyLamb
    The grades probably going from 0 to 10 .
    Probably. But I've learned not to make assumptions from peoples' questions on here For instance, maybe it's percentage of wrong or right answers divided by 10. Who knows?
    If you understand what you're doing, you're not learning anything.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Here's a hint

    1. char chart[10][10];
    2. Fill it with spaces
    3. Fill in the stars, as you would say drawing the thing on graph paper
    4. print it all out.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #12
    Registered User
    Join Date
    Feb 2005
    Posts
    21
    I just handed in an assignment like this last week for my programming in c class. It's just a simple histogram.
    Code:
    void histogram(double input[],double range, double max, double min,char fname[], int n)
    {
     	double storage_bins[22];
    	double factor;
    	double top;
    	double bottom;
    	double increment;
    	double top2 ;
    	double minimum;
    	double scale;
    	double cur_value;
    	double stars_to_print;
    	int i;
    	int j;
    	int max_hist;
    	int line;
    	int sum = 0;
    	system("cls");
            factor = factor_function(range);
            top = ceil(max*factor)/factor;
    	top2 = top;
            bottom = floor(min*factor)/factor;
            increment = (top-bottom)/10.;
    	printf("Histogram for %s\n", fname);
    	/* 1. Find the number of occurances of a file between certain ranges*/
    	minimum = top - increment/2.;
    	for(i = 0; i < 22; i ++)
    	{
    		if(i == 0)
    		{
    			for(j = 0; j < n; j++)
    			{
    				if(input[j] == top2)
    					sum +=1;
    			}
    		storage_bins[i] = sum;
    	
    		}
    		else
    		{			
    				
    			for(j = 0; j <n; j ++)
    			{
    		
    				if(input[j] <= top2 && input[j] > minimum)
    				{
    					sum += 1;
    				}
    			storage_bins[i] = sum;
    			}
    		
    	
    			top2 = top2 - increment/2.;
    		minimum = minimum - increment/2;
    		}
    	sum = 0;
    		
    		
    	
    	}
    	
      	/* 2. Calculate the number of stars to print for each bin*/
    
    	max_hist = storage_bins[0];
    	for (i=1; i<22; i++)
    	{
    		if(storage_bins[i]>max_hist)
    			max_hist = storage_bins[i];
    
    	}
    	
    	scale = max_hist/60.;
    	for (line=0; line<21; line++)
    		storage_bins[line] = storage_bins[line]*scale +.5;
    	/* 3. Print the Histogram and the stars. */
    
    
    	for(line=1, cur_value=top; line<= 21; line++, cur_value-=increment/2.)
    	{
    		//if line is odd, print the current value.
    		if(line%2)
    			printf("%f\t", cur_value);
    		else
    		//if line is even don't print a value. shows a space
    			printf("\t\t");
    
    		//prints the vertical line
    		printf("| ");
    		//calculates how many stars to print for the data in the current range
    		stars_to_print = storage_bins[line-1] * scale;
    		//prints stars
    		for(i=0;i < stars_to_print; i ++)
    			printf("*");
    		
    	
    	
    		printf("\n");
    	}
    
    	printf("press any key to continue...");
    	getche();
    
    }
    hope this helps

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I just handed in an assignment like this last week for my programming in c class.
    And how does that help the OP?

    We try to help people understand what they're trying to do - however difficult it might seem initially. Spoon-feeding answers is in no-ones long term interest.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  14. #14
    Registered User
    Join Date
    Feb 2005
    Posts
    21
    yea, I'm very sorry. I read that on the homework for the messages. I was just too excited that i knew how to do it. next time i will be more careful. If an admin would like to take down that last post go ahead...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hierarchy Chart software suggestions?
    By MatthewDoucette in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 03-09-2005, 01:05 PM
  2. Need help regarding ActiveX Chart Object
    By Hankyaku in forum C++ Programming
    Replies: 2
    Last Post: 02-19-2005, 04:38 PM
  3. How to draw Excel horizontal bar chart?
    By CLearner in forum C Programming
    Replies: 2
    Last Post: 11-09-2004, 11:16 PM
  4. Drawing a simple chart?
    By C++NewUser in forum C++ Programming
    Replies: 1
    Last Post: 09-05-2002, 07:45 AM
  5. outputting a ASCII chart
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 02-15-2002, 11:55 AM