Hey guys, I've started building a program for college, everything was running really smooth and I've started to pick things up in the past couple days, but for the life of me I cannot find where I have a syntax error, neither can my friends :/ I've tried looking up methods to help finding missing parenthesis, by properly indenting work and such but still no luck, here's the code in question. Please help D: I also realise there's no getchar(); return 0; at the end, I havent added the back into the code as I was trying to remove clutter to make it as easily read as possible.

#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;

        }
}

}

Recommended Answers

All 3 Replies

If you're taking advice, don't use conio.h. It's non-standard and really not necessary (and you're not even using anything from it, so you've no reason to include it here).

I see you've put this in the C++ forum, but you are clearly coding in C. Is that deliberate?

Anyway, you don't have to guess at syntax errors. The compiler will tell you. Here is what a compiler says:

65:1: error: expected ‘while’ before ‘}’ token

So, line 65, column 1. Expected a while. Why would it be expecting a while? I see that you've got a do-while loop, the do is on line 44, and the while is on line.... oh, nowhere. Well, that would explain it then. Read about the do-while loop here - http://www.cplusplus.com/doc/tutorial/control/ - half way down.

I also realise there's no getchar(); return 0; at the end,

That's a common kludge used when writing programs designed to be run from the terminal, when you know you're not going to run them from a terminal. It's not some kind of compulsory rule.

Syntax errors come with a line and column number as well as some indiciation of what's missing (or what's there that shouldn't be). So to find a syntax error you should look around the given line and column for anything that might fit the error message.

If the message is about a missing or superfluous }, it indeed makes sense to indent your code to find it (in fact that always makes sense if for no other reason than that we won't get a migraine when reading your code).

Moschops, you are a legend, thank you so much. I've fixed my errors and now it all works perfectly, Sepp2k, thank you as well with your help I indented my work again which cleared it up so much. You're both awesome!

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.