Hi, I am an Uber-noob at C programming!! HELP PLEASE

This is a discussion on Hi, I am an Uber-noob at C programming!! HELP PLEASE within the C Programming forums, part of the General Programming Boards category; Hi, really new to C programming and I need help writing this program that a user inputs three test scores ...

  1. #1
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108

    Unhappy Hi, I am an Uber-noob at C programming!! HELP PLEASE

    Hi, really new to C programming and I need help writing this program that a user inputs three test scores and then is added and then the average is calculated. The problem is I keep getting these errors and I have no idea what the problem is.

    The errors are posted as follows:
    XTCREDIT.c:13:error:expected identifier or a^(a^ before a^chara^)
    XTCREDIT.c:16:error:a^DRAWLINESa^ (first use in this function)
    XTCREDIT.c:16:errorEach undeclared identifier is reported only once for each function it appears in.)
    XTCREDIT.c:21:a^combinedNamea^ undeclared (first use in this function)


    Here is my code:
    Code:
    #include<stdio.h>
    #include<string.h>
    #define addr(var) &var
    #define REPORTHEADINGS1 "  STUDENT    T1    T2     T3    AVG \n"//Heading of the program
    #define REPORTHEADINGS2 "  =======    ==    ==     ==    ===\n"//Heading of the program
    #define REPORTFORMAT    "  %-10s%3d%7d%7d%8.2f\n "//how much space each word is separated by another 
    
    
    void DrawLines(void);//function to draw lines 
    
    int main(void)
    {
     char ln[15+1], fn[15+1], char combinedName[30+1]; 
     int t1,t2,t3;//these are the three test scores of the tests taken
     float avg;//the avg calculated
     printf(DRAWLINES);
     printf("Enter the student's first name");
     scanf("%s", fn);
     printf("Enter the student's last name");
     scanf("%s", ln);
     strcpy(combinedName, ln);
     strcat(combinedName, ", ");
     strcpy(combinedName, fn);
     print("Enter the student's three(3) test scores seperate with space ");
     scanf("%d%d%d", addr(t1), addr(t2), addr(t3));
     avg=(t1 +t2+t3)/3.0;
     printf(DRAWLINES);
     printf(REPORTHEADINGS1), printf(REPORTHEADINGS2);
     printf(REPORTFORMAT, combinedName, t1,t2,t3,avg);
     fflush(stdin);
     printf(" Press any key to continue....\n"), getchar();
     return (0);
    }
    void Drawlines()
    {
     printf("======================================");
    }

    Notes: ln=last name of the student, fn=first name of the studen, combinedName is the full name of the student separated by a comma.

    P.S: if there is anything that i haven't explained please tell me. Thank you much appreciated.
    Last edited by Salem; 05-02-2010 at 12:48 PM. Reason: fixed tags

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    1) You are repeating the word char in the declaration of the last char array.

    2) DRAWLINES is not a variable. It is a function. So call it, instead of printing it.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > printf(DRAWLINES);
    What's this do?

    If you want to call the function, just write it's name.
    DrawLines();


    Oh, and see the FAQ on fflush(stdin)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Claudiu:Thank you for the help on the function Claudiu, but its still not working.


    Salem:Yes its to printf("==========="); I have changed the way I wrote it but the program still doesn't work. I don't see anything wrong then again I'm crappy at C programming.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Post your current code, so we can see what's up with it.

  6. #6
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Okay I will

  7. #7
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    #include<stdio.h>
    #include<string.h>
    #define addr(var) &var
    #define REPORTHEADINGS1 " STUDENT T1 T2 T3 AVG \n"
    #define REPORTHEADINGS2 " ======= == == == ===\n"
    #define REPORTFORMAT " %-10s%3d%7d%7d%8.2f\n "


    void DrawLines(void);

    Code:
    int main(void)
    {
     char ln[15+1], fn[15+1], char combinedName[30+1];
     int t1,t2,t3;
     float avg;
     printf(DRAWLINES);
     printf("Enter the student's first name");
     scanf("%s", fn);
     printf("Enter the student's last name");
     scanf("%s", ln);
     strcpy(combinedName, ln);
     strcat(combinedName, ", ");
     strcpy(combinedName, fn);
     print("Enter the student's three(3) test scores seperate with space ");
     scanf("%d%d%d", addr(t1), addr(t2), addr(t3));
     avg=(t1 +t2+t3)/3.0;
     printf(DRAWLINES);
     printf(REPORTHEADINGS1), printf(REPORTHEADINGS2);
     printf(REPORTFORMAT, combinedName, t1,t2,t3,avg);
     fflush(stdin);
     printf(" Press any key to continue....\n"), getchar();
     return (0);
    }
    void Drawlines()
    {
     printf("======================================");
    }

    As requested by Adak

  8. #8
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    You didn't change anything.

    Call the function Drawlines() instead of printfing it.

    Remove the second char keyword from your declaration of combinedName on the first line of main().

    Also never fflush stdin.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    In your variable declarations, you have:

    char variable, char variable2;

    Which is illegal. remove the second char word, completely.

    You have DRAWLINES instead of DrawLines, in two places, including in printf() calls. You have to watch your upper or lower case letters - C is picky. And you can't call a function through a printf(FunctionName).

    Just use:

    FunctionName();

    and include your variables you want to pass, if any.

  10. #10
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    I found the problem of why it was working it was right under my nose the whole time. I had the name of the function prototype different from the function call and different from the actual function. Stupid me. Thank you guys for helping me. Much appreciated.

  11. #11
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Yes it was also that in the variable declaration I had put it that way as well that was causing the problem.

    Claudiu: I did change it, but I didn't FTP the changed code that I was supposed to repost

    Adak:Thank you. I saw it and I said "oh that was the problem".

    I make dumb mistakes like that. Thank you guys.

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Second to the last line in main(), you have a comma instead of a semi-colon after the

    "press any key to continue"), <<==should be semi-colon

    With your program, the printout is very bad. printout's are things you need to be able to quickly adjust, and see what you are adjust them TO (the lines immediately above or below.

    Having your printout format in define statements, is not as good as it might seem. For formatting, it wastes a lot of time.

    You're welcome!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Noob needs help :)
    By Cursius in forum C++ Programming
    Replies: 4
    Last Post: 12-11-2009, 03:19 PM
  2. Noob printf question
    By lolguy in forum C Programming
    Replies: 3
    Last Post: 12-14-2008, 07:08 PM
  3. A bunch of REALLY uber noob questions
    By mcmasterballer in forum C Programming
    Replies: 1
    Last Post: 05-02-2008, 01:43 PM
  4. noob here
    By lilhawk2892 in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2005, 10:12 AM
  5. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 08:49 AM

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