Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I want to write a program that gets the user to enter 15 integers, The numbers entered must be from 1 to 5. But this doesn't need to be checked. I need to add each number entered into an array. And I must then write a function that can receive a reference to this array, and the number of items in the array. The function should traverse through the array passed to it and count the number of times the values 1 to 5 have been stored. The function should then display these counts with suitable messages.
Can someone help me with this?

A basic example to get you going..
void Total(int array[], int total[]);int main()
{
int temp[10] = {3,2,2,5,1,1,2,3,4,5};
int temp2[5] = {0,0,0,0,0};Total(temp, temp2);
for(int j=0; j5; j++){
cout "Number of " j+1 "s: " temp2[j] endl;
}system("PAUSE");
return 0;
}void Total(int array[], int total[]){
for(int i=0; i10; i++){if(array[i] == 1){
total[0]++;
} else if(array[i] == 2){
total[1]++;
} else if(array[i] == 3){
total[2]++;
} else if(array[i] == 4){
total[3]++;
} else if(array[i] == 5){
total[4]++;
}
}
}

char *title[10], char movie[50];
void store_movie(int num)
{
int i=0;
char additional[50];
strcpy(additional, movie);
//the buy->mov_title is from a
//previous function
title[i] = additional;
i++;
}Can anyone please help, advise on how can I store a few strings. Let's say the first additional copied is 'hello', I would like to store 'hello' into title[0], then second call, title[1] = 'world', title[2] = 'goodbye'.
Is this possible?
Thanx!

![]() |
Auto shut of
|
class description and imp...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |