Data has no class

This is a discussion on Data has no class within the C Programming forums, part of the General Programming Boards category; When i compile the following code, i get data definition has no type or storage class also the average is ...

  1. #1
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751

    Data has no class

    When i compile the following code, i get
    data definition has no type or storage class
    also the average is always zero. I know its late, but what logic am i missing.

    Code:
    #include <stdio.h>
    
    int count;
    float grade, total =0; average=0;
    
    
    
    int main()
    
    {
    
        for(count = 1; count <=5; count++)
        {
           printf("Enter grade number %d: ", count);
           scanf("%f", &grade);
           total = total + grade;
           average = total / count;
           printf("Your average is %f :\n", average);
    
         }
    
    system("pause");
    return 0;
    
    }

  2. #2
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    Code:
    #include <stdio.h>
    
    int count;
    // ; in the next line should be , a typo I guess?
    float grade, total =0,  average=0;
    
    
    
    int main()
    
    {
    
        for(count = 1; count <=5; count++)
        {
           printf("Enter grade number %d: ", count);
           scanf("%f", &grade);
           total = total + grade;
           average = total / count;
           printf("Your average is %f :\n", average);
    
         }
    
    system("pause");
    return 0;
    
    }

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161

    Re: Data has no class

    Originally posted by caroundw5h
    When i compile the following code, i get

    also the average is always zero. I know its late, but what logic am i missing.

    Code:
    #include <stdio.h>
    
    int count;
    float grade, total =0; average=0;
                  error  ^ need , 
    
    
    
    int main()
    
    {
    
        for(count = 1; count <=5; count++)
        {
           printf("Enter grade number %d: ", count);
           scanf("%f", &grade);
           total = total + grade;
           average = total / count;
           printf("Your average is %f :\n", average);
    
         }
    
    system("pause");
    return 0;
    
    }
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    you also need to assign it to .0 also since it is a float

  5. #5
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    thank you for your response. Thank god it wasn't a logic error.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >you also need to assign it to .0 also since it is a float
    I assume you mean initialize with 0.0 instead of 0. In that case there's no need, 0 is automatically converted to the appropriate floating-point value.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 11:13 AM
  2. data structure design for data aggregation
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-20-2008, 07:43 AM
  3. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

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