Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,911 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,185 people online right now. Registration is fast and FREE... Join Now!




RUSH on array

 
Reply to this topicStart new topic

RUSH on array

remix32
21 Jan, 2008 - 11:14 PM
Post #1

New D.I.C Head
*

Joined: 21 Jan, 2008
Posts: 15

Here's the goal
to create a program that ask for the no. of student&print the horizontal histogram.
sample output:
No. of student:10
Test scores:50 41 42 49 48 50 44 46 47 45
histogram:
50-**
49-*
48-*
47-*
46-*
45-*
44-*
43-
42-*
41-*

i tried doing something but I'm a little bit confuse
CODE

#include<stdio.h>
main(){
int i,student,a[60],b[60],x;

    printf("Enter No. of student:");
    scanf("%d",&student);
    
    for(i=0;i<student;i++){
        printf("Enter score:");
        scanf("%d",a[i]);
        if(a[i]==a[i]){
            b[i]=a[i];
            }
        }
    for(i=50;i>=30;i--){
        for(x=0;x<student;x++){
        printf("%d",b[x]);
        }
    }
    }
            
    

User is offlineProfile CardPM
+Quote Post

VernonDozier
RE: RUSH On Array
22 Jan, 2008 - 03:28 AM
Post #2

New D.I.C Head
*

Joined: 6 Jan, 2008
Posts: 46

Well, it looks like you are storing the number of each score in the integer array b? In other words, if 3 students scored 45, then b[45] will equal 3 when you are done tallying scores? All scores must be between 30 and 50, inclusive? If this is correct, I would start by initializing the b array from 30 to 50 to 0, as in:

CODE

for (i = 30; i <= 50; i++)
     b[i] = 0;


You can change your tally code to something like this:

CODE

for(i=0;i<student;i++)
{
        printf("Enter score:");
        scanf("%d",a[i]);
        b[a[i]]++;
}


That would store all the score tallies in the b array and set up the b array for display purposes later in the program.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 01:45PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month