Page 1 of 1

## 5 Replies - 921 Views - Last Post: 28 November 2007 - 01:29 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=38259&amp;s=26c73721c3ccbf81a5ec2c4752ded1ce&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 slippy

Reputation: 0
• Posts: 11
• Joined: 26-November 07

Posted 27 November 2007 - 02:29 PM

```#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

void start(char x[]); //function prototype
void fillit(char x[], int SIZE, int&, int&, int&, int&, int&);
const int SIZE = 80;

int main() {
int num_a=0, num_e=0, num_i=0, num_o=0, num_u=0;
char x[SIZE];

start(x);
fillit(x, SIZE);

cout << "A occured " << num_a << " times" << endl;
cout << "E occured " << num_e << " times" << endl;
cout << "I occured " << num_i << " times" << endl;
cout << "O occured " << num_o << " times" << endl;
cout << "U occured " << num_u << " times" << endl;
}
void start(char x[SIZE]) {
cout << "Input a sentence up to " << SIZE << " characters long, and I will te\
ll you how many times each vowel occurs in it." << endl;
cin.getline(x, SIZE);
}

void fillit(char x[SIZE] int &num_a, int &num_e, int &num_i, int &num_o, int &n\
um_u) {
int index = 0;
int length = strlen(x);
while (index < length){
if(x[index] == 'a'){
num_a++;
}
if (x[index] == 'e'){
num_e++;
}
if (x[index] == 'i'){
num_i++;
}
if (x[index] == 'o'){
num_o++;
}
if (x[index] == 'u'){
num_u++;
}
index++;
}
}
```

now i'm really frustrated.
Ive been trying to finish an assignment all day and i havnt finished a single thing. I don't understand functions for the life of me, i get almost everything else but functions. WHY oh WHY won't this compile?! i keep getting errors no matter WHAT i do to my prototype OR the function itself. very disheartened, very frustrated

Is This A Good Question/Topic? 0

## Replies To: frustrated about functions

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

Posted 27 November 2007 - 03:05 PM

### #3 foohoo

Reputation: 2
• Posts: 41
• Joined: 10-August 07

Posted 27 November 2007 - 03:06 PM

Try this:

```#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

void start(char x[]); //function prototype
void fillit(char x[], int&, int&, int&, int&, int&);
const int SIZE = 80;

int main() {
int num_a=0, num_e=0, num_i=0, num_o=0, num_u=0;
char x[SIZE];

start(x);
fillit(x, num_a, num_e, num_i, num_o, num_u);

cout << "A occured " << num_a << " times" << endl;
cout << "E occured " << num_e << " times" << endl;
cout << "I occured " << num_i << " times" << endl;
cout << "O occured " << num_o << " times" << endl;
cout << "U occured " << num_u << " times" << endl;

return 0;
}
void start(char x[SIZE]) {
cout << "Input a sentence up to " << SIZE << " characters long, and I will tell you how many times each vowel occurs in it." << endl;
cin.getline(x, SIZE);

}

void fillit(char x[SIZE], int &num_a, int &num_e, int &num_i, int &num_o, int &num_u) {
int index = 0;
int length = strlen(x);
while (index < length){
if(x[index] == 'a'){
num_a++;
}
if (x[index] == 'e'){
num_e++;
}
if (x[index] == 'i'){
num_i++;
}
if (x[index] == 'o'){
num_o++;
}
if (x[index] == 'u'){
num_u++;
}
index++;
}
}

```

What i have done is put a
``` return 0;
```
in your main as it has to return an "int"
after that i removed the first "int" from your "fillit()" because you dont need to supply it with "SIZE" and after that it worked, you had done all the hard work! the first time i ran it i got the wrong output (wierd?!?) but everytime since it was ok!

hope this helps!

Foo

### #4 slippy

Reputation: 0
• Posts: 11
• Joined: 26-November 07

Posted 28 November 2007 - 09:19 AM

I did what you said foo, but got errors.

revised code:

```#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

void start(char x[]); //function prototype
void fillit(char x[], int&, int&, int&, int&, int&);
const int SIZE = 80;

int main() {
int num_a=0, num_e=0, num_i=0, num_o=0, num_u=0;
char x[SIZE];

start(x);
fillit(x, num_a, num_e, num_i num_o num_u);

cout << "A occured " << num_a << " times" << endl;
cout << "E occured " << num_e << " times" << endl;
cout << "I occured " << num_i << " times" << endl;
cout << "O occured " << num_o << " times" << endl;
cout << "U occured " << num_u << " times" << endl;
return 0;
}
void start(char x[SIZE]) {
cout << "Input a sentence up to " << SIZE << " characters long, and I will te\
ll you how many times each vowel occurs in it." << endl;
cin.getline(x, SIZE);
}

void fillit(char x[SIZE], int &num_a, int &num_e, int &num_i, int &num_o, int &\
num_u) {
int index = 0;
int length = strlen(x);
while (index < length){
if(x[index] == 'a'){
num_a++;
}
if (x[index] == 'e'){
num_e++;
}
if (x[index] == 'i'){
num_i++;
}
if (x[index] == 'o'){
num_o++;
}
if (x[index] == 'u'){
num_u++;
}
index++;
}
}

```

these were the errors:
```lab6.cxx: In function `int main()':
lab6.cxx:15: error: expected `)' before "num_o"
lab6.cxx:7: error: too few arguments to function `void fillit(char*, int&, int&,
int&, int&, int&)'
lab6.cxx:15: error: at this point in file

```

This post has been edited by slippy: 28 November 2007 - 09:27 AM

### #5 skaoth

Reputation: 91
• Posts: 601
• Joined: 07-November 07

Posted 28 November 2007 - 09:34 AM

When you call the fillit() function you need to add a "," between the parameters you are passing in.

### #6 slippy

Reputation: 0
• Posts: 11
• Joined: 26-November 07