error on declaring int

This is a discussion on error on declaring int within the C Programming forums, part of the General Programming Boards category; How can I declare M? There will be 2 errors if I write int M syntax error before int m ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    16

    error on declaring int

    How can I declare M?
    There will be 2 errors if I write int M

    • syntax error before int
    • m undeclared (first use in this fuction)


    Heres the code-

    Code:
    float calculate_quiz()
         {
               float quiz, total=0;
               
               for (m=0; m<3; m++)
               {
                printf("\nQuiz %d <5M>: ", (m+1));
                scanf("%f", &quiz[m]);
                total = total + quiz[m];
               }       
                return ((total/15)*10);
         }
    Anyone can help out? thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The same way you declared quiz:
    Code:
    float calculate_quiz()
         {
               float quiz, total=0;
               int m;
               for (m=0; m<3; m++)

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by karipap View Post
    How can I declare M?
    There will be 2 errors if I write int M

    • syntax error before int
    • m undeclared (first use in this fuction)


    Heres the code-

    Code:
    float calculate_quiz()
         {
               float quiz, total=0;
               
               for (m=0; m<3; m++)
               {
                printf("\nQuiz %d <5M>: ", (m+1));
                scanf("%f", &quiz[m]);
                total = total + quiz[m];
               }       
                return ((total/15)*10);
         }
    Anyone can help out? thanks
    I think you might be declaring m inside the loop like this
    Code:
    for(int m=0;m<3;m++)
    In this case the compiler throws an error(mine also). I think this is not the standard way to do. Is this so? If anybody could throw some light on this matter.
    Also if i declare any variable at any place in main except immediately after the starting curly brace, it shows an error . Why is this so? Is it necessary to declare all the variables at one place just after the starting brace of main?
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    Registered User
    Join Date
    Apr 2009
    Location
    Russia
    Posts
    116
    Code:
    cc -std=c99 -Wall main.c -o test
    ok
    it is not conform to C89

    Code:
    ‘for’ loop initial declaration used outside C99 mode

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory leak
    By aruna1 in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2008, 10:28 PM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  4. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  5. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21