Not an allowed type?

Hello all

I'm hoping someone can explain why I get the error 'not an allowed type'   in the bit  'choice = menu();'  I'm very new to c++ as you most probably guessed.  

Thanks in advance

Karen

#include<conio.h>       //required for getch()
#include<iostream.h>    //required for cin and cout
#include <stdio.h>

void instructions (void);
void playgame (void);
void matrix(void);
void menu (void);

//Main() is where program execution starts
void main (void)
  {
  int choice = 0;

  char key;  //define a character called key
  do
    {
    choice = menu();
    clrscr();
    menu();
{
    do
   {
   if(choice == 1)
   {
   instructions();
   }
   else if (choice == 2)
   {
   playgame();
   }
   while (choice != 3);
   clrscr();
   }// End of main
karen4444Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Harisha M GEngineerCommented:
Hi karen4444,
    menu is having a void datatype as return value...
void menu (void);
    So you can't assign it to any variable.

Bye
---
Harish
Harisha M GEngineerCommented:
karen4444,
    If you want to change that, try
int menu (void);
karen4444Author Commented:
Thanks - that seems to have solved that one.  But I get the same problem further down when I try to define int menu (void) - what now???


int menu (void)
    {
    int option = 0;
    char key;
    clrscr();



Karen
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Harisha M GEngineerCommented:
Please post the full code.
karen4444Author Commented:
I haven't nearly finished it yet! - but this is where I've got to so far. I am doing it bit by bit (not sure if this is the correct approach or no)


#include<conio.h>       //required for getch()
#include<iostream.h>    //required for cin and cout
#include <stdio.h>

void instructions (void);
void playgame (void);
void matrix(void);
int menu (void);

//Main() is where program execution starts
void main (void)
  {
  int choice = 0;

  char key;  //define a character called key
  do
    {
    choice = menu();
    clrscr();
    menu();

   {
    do
   {
   if(choice == 1)
   {
   instructions();
   }
   else if (choice == 2)
   {
   playgame();
   }
   while (choice != 3);
   clrscr();
   }



    int menu (void)
    {
    int option = 0;
    char key;
    clrscr();
    cout << "\n\n\n\n\n\n\t\t\t\tTIC TAC TOE\n\n\n\t\t";
    cout << "Think You Can Win a Game of Tic Tac Toe?\n\n\n\t\t";
    cout << "Please choose one of the following options...\n\n\n";
    cout << "\n\tView Instructions     Press '1'";
    cout << "\n\tStart New Game      Press '2'";
    cout << "\n\tExit Program           Press '3'";

    do
      {
      key= getch();//input choice
      }
      while (key!='1' && key!='2' && key!='3');


      if (key=='1') option = 1;
      if (key=='2') option = 2;
      if (key=='3') option = 3;

      return choice;
}





    void instructions (void)
     {
     cout << "\n\n\tThe object of the game is to get 3 matching symbols in a row";
     }

      void playgame (void)

      {
        clrscr();
        hline(5,10,17,4); //we call the function here
        hline(5,16,17,4);
        vline(10,5,17,4);
        vline(16,5,17,4);
Harisha M GEngineerCommented:
I am not sure whether the logic of the program is correct or not... but few points...

Maintain neat code with indentation so that it becomes easy for the reader and for you too while debugging.
You have assingned the pressed key to 'option' but the return value is 'choice'.


Here is a modified code. Check and ask if you have any doubts :)



#include <conio.h>       //required for getch()
#include <iostream.h>    //required for cin and cout
#include <stdio.h>

void instructions (void);
void playgame (void);
void matrix(void);
int menu (void);

//Main() is where program execution starts
void main (void)
{
     int choice = 0;

     char key;  //define a character called key
     do
     {
          choice = menu();
          clrscr();

          if(choice == 1)
               instructions();
          else if (choice == 2)
               playgame();

     }while (choice != 3);
     
     clrscr();
}

int menu (void)
{
     int option = 0;
     char key;
     clrscr();
     cout << "\n\n\n\n\n\n\t\t\t\tTIC TAC TOE\n\n\n\t\t";
     cout << "Think You Can Win a Game of Tic Tac Toe?\n\n\n\t\t";
     cout << "Please choose one of the following options...\n\n\n";
     cout << "\n\tView Instructions     Press '1'";
     cout << "\n\tStart New Game      Press '2'";
     cout << "\n\tExit Program           Press '3'";

     do
     {
          key= getch();                                   //input choice
     }while (key!='1' && key!='2' && key!='3');


     if (key=='1') option = 1;
     if (key=='2') option = 2;
     if (key=='3') option = 3;

     return choice;
}

void instructions (void)
{
     cout << "\n\n\tThe object of the game is to get 3 matching symbols in a row";
}

void playgame (void)
{
     clrscr();
     hline(5,10,17,4); //we call the function here
     hline(5,16,17,4);
     vline(10,5,17,4);
     vline(16,5,17,4);
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Harisha M GEngineerCommented:
In the menu() function, int option = 0 and return choice are not at all required. Moreover, you haven't declared the choice variable there !!
aib_42Commented:
>     if (key=='1') option = 1;
>     if (key=='2') option = 2;
>     if (key=='3') option = 3;

Why not just do "option = key;"?
In fact, don't use option at all, use key.

>     return choice;

You probably mean "return option;". Why not do "return key;"?

You also have a "char key" in main() that you're not using.
Harisha M GEngineerCommented:
Thanks karen4444

aib_42, you are wrong.. key is a char and option/choice is an int.
If you really need that, you might have to do
return key - 48;
aib_42Commented:
Oops, sorry, must be the natural morphine my brain's producing to stop this toothache.

Yea '1' '2' are character constants, though I'd advise (key - '0') instead of (key - 48), a bit more portable.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.