1

I am 13 and learning c programming and so I have an incredibly basic understanding of c programming. I'm learning how to 'Display Variable Values',I'm using VERY basic code but when i try to compile it using GNU (MinGW) it tells me...

vars.c:4:1: error: expected declaration specifiers or '...' before '(' token

Please may someone tell me how i could fix this!

This is the code:

#include <stdio.h> 

int main(
(printf( "Integer is %d \n",num);
(printf( "Values are %d and %f \n",num,pi);
(printf( "%%7d displays %7d \n",num);
(printf( "%%07d displays %07d \n",num);
(printf( "Pi is approximately %1.10f \n",pi);
(printf( "Right-aligned %20.3f rounded pi \n",pi);
(printf( "Left-aligned %-20.3f rounded pi \n",pi);
return 0 ;)
)
({
int num = 100;
double pi = 3.1415926536;
(return 0 ;)
})

4 Answers4

2

The syntax you are using is pretty much entirely wrong starting on the third line. You never finished declaring the arguments of main and you have tons of extra parentheses. You should Google for "c hello world" and try to run those examples so you can get a feel for what C code looks like. Here is an example that might help:

#include<stdio.h>

int main()
{
    int num = 100;
    printf("Hello World\n");
    printf("Integer is %d\n",num);
    return 0;
}
David Grayson
  • 84,103
  • 24
  • 152
  • 189
  • Thank you I think I'm getting in ahead of myself! May have to read up a bit!!!!! –  Apr 11 '13 at 22:23
2

I'm not sure where you came up with this code, but I'm assuming you intended to type the following:

#include <stdio.h>

int main(void)
{
        int num = 100;
        double pi = 3.1415926536;

        printf( "Integer is %d \n",num);
        printf( "Values are %d and %f \n",num,pi);
        printf( "%%7d displays %7d \n",num);
        printf( "%%07d displays %07d \n",num);
        printf( "Pi is approximately %1.10f \n",pi);
        printf( "Right-aligned %20.3f rounded pi \n",pi);
        printf( "Left-aligned %-20.3f rounded pi \n",pi);

        return 0 ;
}

Try to find an online C programming tutorial and work your way through it. It will prove to be much more satisfactory than trial and error.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
Bryan Olivier
  • 5,207
  • 2
  • 16
  • 18
0

At least three problems:

1) completely unnecessary parenthesis

2) Uninitialized variables

3) ???Trying to create a lambda in your main()???

Suggested modifications:

#include <stdio.h> 

int main() {
  int num = 100;
  double pi = 3.1415926536;

  printf( "Integer is %d \n",num);
  printf( "Values are %d and %f \n",num,pi);
  return 0 ;
}
paulsm4
  • 114,292
  • 17
  • 138
  • 190
0

Working version of your code:

#include <stdio.h> 

int main() {
  int num = 100;
  float pi = 3.1415926536;

  printf( "Integer is %d \n",num);
  printf( "Values are %d and %f \n",num,pi);
  printf( "%%7d displays %7d \n",num);
  printf( "%%07d displays %07d \n",num);
  printf( "Pi is approximately %1.10f \n",pi);
  printf( "Right-aligned %20.3f rounded pi \n",pi);
  printf( "Left-aligned %-20.3f rounded pi \n",pi);

  return 0;
}
rmn
  • 2,386
  • 1
  • 14
  • 21