-3
#include "stdafx.h"
#include <iostream>
#include <string>

int isVowel(char &a, int &counter);
bool enterAnotherOne();
void  outputResult(int &counter);
bool goAgain();


using namespace std;

 int main() {
     int counter = 0;
      char a;

      do
      {
          do
          {
              void enter(a);
              int isVowel(counter);
              void outputResult();

          } while (enterAnotherOne());

      } while (goAgain());



    return 0;
}// Function main()
// ===================


 void enter() {
     char a;
     cout << "Enter a letter. ";
     cin >> a;

 }


 }// Function Letter()
//  ===========================


 int isVowel(char &a, int &counter) {
     counter = 0;

     if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u' || a == 'y')
     {
         counter++;
     }   

     return counter;
 }// isVowel()
//  ============== 

 bool enterAnotherOne() {
     char a;

     cout << "Would you like to enter another letter? ";
     cin >> a; 

     if (a == 'y')
     {
         return true;
     }
     else
     {
         return false;
     }
 }




 void outputResult(int &counter) {
     cout << "The number of vowels that you entered are " << counter << endl;

 }// outputResult()
//  ===================

 bool goAgain() {
     char a;

     cout << "Would you like to go again? ";
     cin >> a;

     if (a == 'y')
     {
         return true;
     }
     else
     {
         return false;
     }
 }

Hey Guys, I was making a program that would count the number of vowels that are entered when inputting random letters. The problem I am having is that, this line:

void enter(a);

it says incomplete type is not allowed and I can't figure out what is wrong with it.

Zubair Amjad
  • 463
  • 2
  • 5
  • 10
  • A call to a function would be something like `isVowel(a, counter)` or `enter(a)` (but the last one doesn't match any declaration...). – Jarod42 Jul 22 '16 at 00:13
  • Please post a [mcve]. – Baum mit Augen Jul 22 '16 at 00:15
  • I recommend not using `stdafx.h` (precompiled headers) for small programs. The changes to the build times are not significant, but the hassles of precompiling the headers increases. Every time any of the precompiled headers change, the headers need to be compiled again. – Thomas Matthews Jul 22 '16 at 00:37

3 Answers3

1
void enter(a); 

is likely being seen by the compiler as either

  1. a declaration of enter as a variable of type void and passing a into the void constructor, and void's not a complete type because you can't make a void. void is nothing.
  2. a declaration of function enter that returns void that expects a parameter of type a passed by value. a would be the incomplete type.

I think the first interpretation is more likely.

Anyway, you likely wanted to call

enter(a); 

But that won't work because the enter function doesn't take any parameters. Let's look at enter for a moment.

void enter() {
    char a;
    cout << "Enter a letter. ";
    cin >> a;
}

This function unfortunately doesn't do much. it reads a character from the user and promptly throws it away. We probably want to use that character, so

char enter() {
    char a;
    cout << "Enter a letter. ";
    cin >> a;
    return a;
}

Now we get a copy of the character returned to the caller. That means

enter(a); 

Should look more like

a = enter(); 

You have similar problems with

int isVowel(counter);
void outputResult();

right below the call to enter.

Unfortunately enter is not visible to main because it is declared after main is declared. I recommend moving the function declaration to above main in the file. You could forward declare enter as you have done with the other functions, but why bother? A forward declaration means you may have two places to change the code if the function changes.

I recommend pulling out your programming textbook and reading the first few chapters to get a better grasp of functions. If you are learning on your own and have no textbook, or if your textbook sucks, The Definitive C++ Book Guide and List may be of use to you.

Side note: There are more than just guys running around here.

Community
  • 1
  • 1
user4581301
  • 33,082
  • 7
  • 33
  • 54
0

This has a few issues with it.

Firstly, you don't seem to prototype the enter function (you don't declare it with the rest of the functions near the top of the code).

Secondly, I think you're trying to call the functions using the code within the do loops, however it's not clear due to the fact that you've put a type before your reference to the functions. If you're trying to call them, you shouldn't mention any types beforehand, so void enter(a); should just become enter(a); (not really, due to the "a", more on that on the next point).

Thirdly, assuming that you were trying to call the functions in that bit of code, as I assumed above, the arguments you're passing in aren't consistent with the way the functions are defined. For example, enter requires no arguments in the function you've created, however when you attempt to call it in the do loop, you're trying to pass in a variable "a" which it isn't prepared for. Checking the other function calls in that block, you'll find it to be inconsistent with those, too.

Fourthly, and building off of the last point, I believe you made the mistake of leaving out the "a" variable being passed into enter, as you reference it whilst within the function however it is never passed in.

Don't be discouraged by this! Keep learning and prosper!

VortixDev
  • 965
  • 1
  • 10
  • 23
0

There's quite a few issues with your code, I've put some meaningful comments in my code to help you. It sounds harsh, but I'm must in a rush, so I'm not trying to be. This will fully compile and run like I think you'd like.

#include "stdafx.h"
#include <iostream>
#include <string>

void enter(char&); /*You forget to put the function prototype here.*/
void isVowel(char &, int &); /*Since you are passing by reference, and NOT using the return value, you don't need have have it return int.*/
bool enterAnotherOne();
void outputResult(int &);
bool goAgain();


using namespace std;

int main() {
    int counter = 0;
    char a;

    do
    {
        do
        {
            enter(a); //you don't need to declare the function type when calling a function :(
            isVowel(a, counter); /*You didn't properly pass the argument here*/
            outputResult(counter); //This needs an argument.

        } while (enterAnotherOne());

        //Did you want to reset the counter? if so, do it here.
        counter = 0;
    } while (goAgain());

    return 0;
}// END OF Function main() /*Make sure you clarify it is the END OF function main().*/
// ===================


void enter(char &letter) { /*This requires an argument to be useful.*/
    cout << "Enter a letter. ";
    cin >> letter;
}
// END OF Function Letter() also, you had an extra bracket, which means this wouldn't compile.
//  ===========================

void isVowel(char &a, int &num) {
    //counter = 0; //if your're coing to pass counter as a argument, why doe this?
    //counter = 0 resets counter back to 0.

    if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u' || a == 'y')
    {
        num++;
    }
}// END OF isVowel()
//  ==============

bool enterAnotherOne() {
    char choice; //give meaningful variable names!

    cout << "Would you like to enter another letter? ";
    cin >> choice;

    if (choice == 'y')
    {
        return true;
    }
    else
    {
        return false;
    }
}//If you're going ot comment END OF on every function, might as well do it here.

void outputResult(int &num) {
    cout << "The number of vowels that you entered are " << num << endl;
}// END OF outputResult()
//  ===================

bool goAgain() {
    char choice;

    cout << "Would you like to go again? ";
    cin >> choice;

    if (choice == 'y')
    {
        return true;
    }
    else
    {
        return false;
    }
}//where's END OF for this function?
NonCreature0714
  • 5,744
  • 10
  • 30
  • 52