Computing.Net > Forums > Programming > C++ Array Program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

C++ Array Program

Reply to Message Icon

Name: Avon
Date: March 10, 2003 at 02:56:59 Pacific
OS: xp
CPU/Ram: 88mhz
Comment:

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?




Sponsored Link
Ads by Google

Response Number 1
Name: gpp
Date: March 10, 2003 at 10:50:00 Pacific
Reply:

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]++;
}
}
}


0

Response Number 2
Name: borelli34
Date: March 10, 2003 at 19:37:46 Pacific
Reply:

Your doing your homework on an 88Mhz computer? What kind of school are you going to?

borelli34


0

Response Number 3
Name: red_evolve
Date: March 15, 2003 at 23:04:18 Pacific
Reply:

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!


0
Reply to Message Icon

Related Posts

See More


Auto shut of class description and imp...



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ Array Program

turbo C++ array program need Help!! www.computing.net/answers/programming/turbo-c-array-program-need-help/8615.html

C++ array help needed www.computing.net/answers/programming/c-array-help-needed/5479.html

c-64 program www.computing.net/answers/programming/c64-program/115.html