Aug 22, 2012 at 3:15pm UTC
I have syntax error here:
// wew.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
#include "conio.h"
using namespace std;
int choice;
char decide;
int mainMenu();
int choices(int choice)
{
switch(choice)
{
case 1:
system("cls");
cout << "Description" << endl << endl;
cout << endl << endl << "Go back to Main Menu (y/n)?"<< endl;
cin >> decide;
if(decide == 'y')
{
mainMenu();
}
break;
case 2:
do
{
system("cls");
cout << "Description" << endl << endl << endl;
cout << endl << endl << "Go back to Main Menu (y/n)?"<< endl;
cin >> decide;
if(decide == 'y')
{
mainMenu();
}
}
return 0;
break;
}
return 0;
}
int mainMenu()
{
system("CLS");
cout << "Main menu" << endl << endl;
cout << "[1]Choice1" << endl;
cout << "[2]Choice2" << endl;
cout << "[3]Choice3" << endl;
cout << endl << "Enter your choice: ";
cin >> choice;
choices(choice);
getch ();
return 0;
}
int main()
{
mainMenu();
}
It says that cpp(46): error C2059: syntax error : 'return'
What should i do and whats wrong in my program?
Last edited on Aug 22, 2012 at 3:19pm UTC
Aug 22, 2012 at 3:26pm UTC
You should make sure you put a while in your do-while loop.
Aug 22, 2012 at 3:34pm UTC
I removed the do-while loop then i got errors
here is my program now:
// wew.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
#include "conio.h"
using namespace std;
int choice;
char decide;
int mainMenu();
int choices(int choice)
{
switch(choice)
{
case 1:
system("cls");
cout << "Description" << endl << endl;
cout << endl << endl << "Go back to Main Menu (y/n)?"<< endl;
cin >> decide;
if(decide == 'y')
{
mainMenu();
}
break;
case 2:
{
system("cls");
cout << "Description" << endl << endl << endl;
cout << endl << endl << "Go back to Main Menu (y/n)?"<< endl;
cin >> decide;
if(decide == 'y')
{
mainMenu();
}
break;
}
case 3:
{
exit(3);
default: "invalid choice";
break;
}
}
int mainMenu();
{
system("CLS");
cout << "Main menu" << endl << endl;
cout << "[1]Choice1" << endl;
cout << "[2]Choice2" << endl;
cout << "[3]Choice3" << endl;
cout << endl << "Enter your choice: ";
cin >> choice;
choices(choice);
_getch ();
return 0;
}
int main()
{
mainMenu();
}
then the errors:
cpp(71): error C2601: 'main' : local function definitions are illegal
cpp(16): this line contains a '{' which has not yet been matched
fatal error C1075: end of file found before the left brace '{' at 'c:\users\chris atienza\documents\visual studio 2010\projects\1\1\1.cpp(16)' was matched
Aug 22, 2012 at 3:36pm UTC
You're missing braces.
If you format your code sensibly with indentations, you'd see that immediately.
Aug 22, 2012 at 3:43pm UTC
cpp(56): error C2447: '{' : missing function header (old-style formal list?)
How to solve this?
Aug 22, 2012 at 3:47pm UTC
Remove the semi-colon at the end of the start of the function definition.
Aug 22, 2012 at 3:56pm UTC
What is system() doing in your code?????