Info :Compiling C:\tmp\lab2.cpp
Warn :  lab2.cpp(56,16):Possible use of 'choice' before definition
Error:  lab2.cpp(60,5):Type mismatch in redeclaration of 'mainProgram()'
Error:  lab2.cpp(60,5):Declaration syntax error

Hi everone, I am new to C++, please help.
After I compile (using borland V5.02), I got these above prolem, please let me know what's wrong and this is my source code:

// Compiler:                Borland C++ V5.02
//
// Program Description:
/////////////////////////////////////////////////////////////////////
// This program will provide the user with quotes from Walt Disney.//
/////////////////////////////////////////////////////////////////////
#include <iostream>
// function declarations...
void programDescription();
char mainMenu();
void mainProgram();
char choice();
/*
 main entry point for the program.
 */
 void main (void)
{
    mainProgram();
}
/*
  programDescription()
  provides a description ()
  Provides a description of the program to the user.
*/
    void programDescription()
   {
   cout <<"This program will display famous quotes" << endl;
   cout <<"make by Walt Disney. Topics are provided" << endl;
   cout <<"in the menu box." << endl << endl ;
   }
/*
mainMenu ()
Provides the main menu for the user to select from.
*/
   char mainMenu()
   {
    char choice;
    cout <<"Please select a topic to view quote:" <<endl <<endl;
    cout <<"1.  Challenge" << endl;
    cout <<"2.  Achievement" << endl;
    cout <<"3.  Overcoming Adversity" << endl;
    cout <<"4.  Ability" << endl;
    cout <<"5.  Persistence" << endl;
    cout <<"6.  Belief" << endl;
    cout <<"E.  Exit the program" << endl << endl;
    cout <<"Your choice:" <<endl;
    cin >> "choice";
    return choice;
    }
   mainProgram ()
  //Function that runs the entire program.
void mainProgram ()
    {
char userChoice; //variable used to store menu choice..
int exit=0;      //flag to quit the program...
void programDescription();   //describe the program to the user...
//loop that allows the user to continue or quit...
do
   {
userchoice = mainMenu ();  // show the menu...
    switch (userchoice)
    {
     case '1':
     cout << endl <<"It's kind of fun to do the impossible."<<endl;
     break;
     case '2':
     cout << endl <<"The way to get started is to quit talking and begin doing."<<endl;
    break;
    case '3':
         cout << endl <<"You may not realize it when it happen, but the kick in the teeth may be"<< endl;
       cout << endl <<"the best thing in the world for you."<<endl;
     break;
     case '4':
     cout << endl <<"If you can dream it, you can do it."<<endl;
     break;
     case '5':
     cout << endl <<"Get a good idea and stay with it. Dog it, and work at it until it's done right."<<endl;
     break;
    case '6':
     cout << endl <<"When you believe in a thing, believe in it all the way, implicitly and unquestionably."<<endl;
     break;
     case 'E'
     case 'e'
    exit = 1;
     default:
     cout << endl << "Sorry, that was not a valid choice." << endl << endl;
     break;
   }
}
}
While (exit !=1);

Thanks in advance.

First off, when you post in the future you should use the code tags to make it way easier to read.

Last time I checked your main() function has to return an int and you have it as a void function.

void main (void)
{
	mainProgram();
}

I don't know if its just because I use Dev-C++ and you have Borland.


You have a line in your mainMenu() function

cin >> "choice"; //this is wrong "choice" is not a variable
cin >> choice; //change to this

In mainProgram() function

char userChoice;
userchoice = mainMenu ();
switch (userchoice)

userchoice and userChoice are two different variables so watch out for typos

and

case 'E'
case 'e'

case 'E': //add a colon to both cases like you did above for all the other case statements
case 'e':

I'm not too sure why you made a function called mainProgram() when if you stuck it's contents into your main() function.

Thanks for your help. This is the first time, that's why I did not know how to post the right way, sorry.
I did the same thing like you said, but problem still happen, I do not know what's going on, could somebody please help???? I have to turn this one in tomorow.
Thank all you guy very much
This is new edit, but still got same error.

// Compiler:                Borland C++ V5.02
    //
    // Program Description:
    /////////////////////////////////////////////////////////////////////
    // This program will provide the user with quotes from Walt Disney.//
    /////////////////////////////////////////////////////////////////////
    #include <iostream>
    // function declarations...
    void programDescription();
    char mainMenu();
    void mainProgram();
    char choice ();
    /*
     main entry point for the program.
     */
     void main (void)
    {
        mainProgram();
    }
    /*
      programDescription()
      provides a description ()
      Provides a description of the program to the user.
    */
        void programDescription()
       {
       cout <<"This program will display famous quotes" << endl;
       cout <<"make by Walt Disney. Topics are provided" << endl;
       cout <<"in the menu box." << endl << endl ;
       }
    /*
    mainMenu ()
    Provides the main menu for the user to select from.
    */
       char mainMenu ()
       {
        char choice;
        cout <<"Please select a topic to view quote:" <<endl <<endl;
        cout <<"1.  Challenge" << endl;
        cout <<"2.  Achievement" << endl;
        cout <<"3.  Overcoming Adversity" << endl;
        cout <<"4.  Ability" << endl;
        cout <<"5.  Persistence" << endl;
        cout <<"6.  Belief" << endl;
        cout <<"E.  Exit the program" << endl << endl;
        cout <<"Your choice:" <<endl;
        cin >> choice;
        return choice;
        }
       mainProgram ()
      //Function that runs the entire program.

       void mainProgram
        {
    char userChoice; //variable used to store menu choice..
    int exit=0;      //flag to quit the program...
    programDescription ();  describe the program to the user...
    //loop that allows the user to continue or quit...
    do
       {
    userChoice = mainMenu ();  // show the menu...
        switch (userChoice)
        {
         case '1':
         cout << endl <<"It's kind of fun to do the impossible."<<endl;
         break;
         case '2':
         cout << endl <<"The way to get started is to quit talking and begin doing."<<endl;
        break;
        case '3':
             cout << endl <<"You may not realize it when it happen, but the kick in the teeth may be"<< endl;
               <<"the best thing in the world for you."<<endl;
         break;
         case '4':
         cout << endl <<"If you can dream it, you can do it."<<endl;
         break;
         case '5':
         cout << endl <<"Get a good idea and stay with it. Dog it, and work at it until it's done right."<<endl;
         break;
        case '6':
         cout << endl <<"When you believe in a thing, believe in it all the way, implicitly and unquestionably."<<endl;
         break;
         case 'E';
         case 'e';
        exit = 1;
         default:
         cout << endl << "Sorry, that was not a valid choice." << endl << endl;
         break;
       }
    }
    }
    While (exit !=1);

After running around, now I got 1 warking and 1 error:

Info :Compiling C:\Documents and Settings\Binh Vo\Desktop\C++\lab2.cpp
Error:  lab2.cpp(100,6):do statement must have while
Warn :  lab2.cpp(101,2):'exit' is assigned a value that is never used

.

new source code:

// Compiler:				Borland C++ V5.02
//
// Program Description:
/////////////////////////////////////////////////////////////////////
// This program will provide the user with quotes from Walt Disney.//
/////////////////////////////////////////////////////////////////////
#include <iostream>
// function declarations...
void programDescription();
char mainMenu();
void mainProgram();
char choice ();
/*
 main entry point for the program.
 */
 void main (void)
{
 	mainProgram();
}
/*
  programDescription()
  provides a description ()
  Provides a description of the program to the user.
*/
  	void programDescription()
   {
   cout <<"This program will display famous quotes" << endl;
   cout <<"make by Walt Disney. Topics are provided" << endl;
   cout <<"in the menu box." << endl << endl ;
   }
/*
mainMenu ()
Provides the main menu for the user to select from.
*/
   char mainMenu ()
   {
	char choice;
	cout <<"Please select a topic to view quote:" <<endl <<endl;
	cout <<"1.  Challenge" << endl;
	cout <<"2.  Achievement" << endl;
	cout <<"3.  Overcoming Adversity" << endl;
	cout <<"4.  Ability" << endl;
	cout <<"5.  Persistence" << endl;
	cout <<"6.  Belief" << endl;
	cout <<"E.  Exit the program" << endl << endl;
	cout <<"Your choice:" <<endl;
	cin >> choice;
	return choice;
	}
   /////////////////////////////////////////
  //Function that runs the entire program.//
  ///////////////////////////////////////////
   void mainProgram()
	{
char userChoice; //variable used to store menu choice..
int exit=0;      //flag to quit the program...
programDescription ();  //describe the program to the user...
//loop that allows the user to continue or quit...
  do
  {
  userChoice = mainMenu ();  // show the menu...
    switch (userChoice)
    {
 	 case '1':
 	 cout << endl <<"It's kind of fun to do the impossible."<<endl;
 	 break;
 	 case '2':
 	 cout << endl <<"The way to get started is to quit talking and begin doing."<<endl;
    break;
    case '3':
 		 cout << endl <<"You may not realize it when it happen, but the kick in the teeth may be"<< endl;
       cout << endl <<"the best thing in the world for you."<<endl;
 	 break;
 	 case '4':
 	 cout << endl <<"If you can dream it, you can do it."<<endl;
 	 break;
 	 case '5':
 	 cout << endl <<"Get a good idea and stay with it. Dog it, and work at it until it's done right."<<endl;
 	 break;
    case '6':
 	 cout << endl <<"When you believe in a thing, believe in it all the way, implicitly and unquestionably."<<endl;
 	 break;
 	 case 'E':
 	 case 'e':
    exit = 1;
  	 default:
 	 cout << endl << "Sorry, that was not a valid choice." << endl << endl;
  	 break;
    }
   }

While (exit !=1);
}

Thank you everybody, I got it, thanks god, I can beable to turn it in tomorow

Thank you everybody, I got it,

I cannot imagine that the above code would compile. One thing I spot is that you write while with a capital W (While). That won't compile for example.

Also: void main

thanks god

So did God give you working code then? :icon_wink:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.