Hey guys, I've recently started learning c++ and all was running really smooth and I've decided I'd like to make a program using switch statements and such, unfortunately for the life of me I can't find where I'm getting a syntax error in my code, I've tried properly indenting my work, and I've had a couple friends look at it, any help would be greatly appreciated. Thank you <3 the error is on line 64 btw :)
#include <stdio.h>
#include <conio.h>
int main()
{
int menu();
printf("\n To commence our program please press the enter key to continue...");
getchar();
system("CLS");
void mainmenu();
char selection;
int menu1;
int number;
{
printf("\n******************************************************");
printf("\n******************************************************");
printf("\n** Hello and welcome to my program! **");
printf("\n** Please select the program you would like to run! **");
printf("\n******************************************************");
printf("\n** - 1. Multiplication table **");
printf("\n** - 2. Program B - **");
printf("\n** - 3. Program C - **");
printf("\n** - 4. Program D - **");
printf("\n** - 5. Exit - **");
printf("\n******************************************************");
printf("\n******************************************************");
printf("\n ");
scanf("%d", &selection);
system("CLS");
switch (selection)
{
case 1:
do
{
int i, j;
printf (" |");
for (i = 1; i <= 10; ++i)
printf ("%#3d ", i);
printf ("\n");
for (i = 1; i < 64; ++i)
printf ("-");
printf ("\n");
for (i = 1; i <= 10; ++i) {
printf ("%#2d |", i);
for (j = 1; j <= 10; ++j)
printf ("%#3d ", i * j);
printf ("\n");
}
break;
}
}
}
Hiya,
Well firstly, lines 7 to 20 is a bit mental. The structure of your code should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
// hash includes
// function declarations
int main()
{
...
...
...
return 0;
}
but for some reason you have your main() declaration, and then your function decs inside this and then you randomly put a opening brace on line 22. If you sort this out i'm sure your error will go away.
I have sorted out odd parenthesis on line 22. Line 64 still gives me a syntax error, I've added the return 0; as well as shifted my declarations where they should be, however the syntax error is now before the return. I'm horridly confused sorry D:
Have you read that link I posted?
Do you now have function declarations before your main(), and are you now calling those functions inside your main function?
Oh, I'm really sorry it's 12am here I'm getting kind of tired, I must've missed it I'm giving it a quick read as we speak but yeah, my decs are now above int main(), now I need to figure out where I should be calling them. Sorry.. LOL
i don't know C at all, but in c++ do(loop) command comes with while. if this was a c++ program, at line 64, i would have to add while condition. though in this case, you don't seem to need loop of any sort. try deleting line 44,45 and 64. did it work?
Well guys, I ended up rewriting the entire program, cleaning it up as Mutexe pointed at and for some reason it all compiles now with no errors or anything, so thanks guys. I really mean it, you've been a huge help :D Tomorrow I will figure out a way to clear the screen once a key has been pressed after it's done printing the table and bring up the main menu again :D
As koopey points out, it might be worth mentioning that if you are wanting to learn C++ it would be better to use C++ constructs/keywords for input and output: http://www.cplusplus.com/doc/tutorial/basic_io/
and to inlude the corresponding header: