Thread: A bit more complicated problem

  1. #1
    Registered User
    Join Date
    Oct 2011

    A bit more complicated problem

    So I'm finally starting to get the hang of the loops and such and we were introduced to a bunch of new stuff today and had to write what to me seemed like a pretty complicated code. I looked at this over and over again and can't really see where I went wrong.

    The purpose of the program is to take 3 scores for bowlers and average their scores, and assign them a rating of 1-4 stars and print the value of their average with their name and rating.

    Any advice to lead me in the right direction will be greatly appreciated!

    #include <stdio.h>
    #include <ctype.h>
    #define MAXWORD 50
    int main(void)
    int n, i, s1=0, s2=0, s3=0, numstars, avg = 0, overall_avg, highest_avg, high_avg, overall_score = 0;
    char w[MAXWORD], name[MAXWORD];
       printf("Enter Number of Bowlers:\n");
       scanf("%d", &n);
       for(i = 1; i <= n; ++i) {
          printf("Enter Bowlers Name:\n");
          scanf("%s", &w);
          printf("Enter 3 Scores for Bowler:\n");
          scanf("%d\n%d\n%d", &s1, &s2, &s3);
          avg = (s1 + s2 + s3)/3;
              if(avg >= 200)
                 numstars = 4;
              if(avg >= 170 && avg <= 199)
                 numstars = 3;
              if(avg >= 125 && avg <= 169)
                 numstars = 2;
              if(avg >= 100 && avg <= 124)
                 numstars = 1;
                 numstars = 0;
          printf("Bowler =  %s\n", w);
          printf("Average= %d\n", avg);
          printf("Number of Stars = %d\n", numstars);
          overall_score += avg;
          if(avg> high_avg) {
            strcpy (name[]) = w;
            avg = highest_avg;
    overall_avg = overall_score / n;
    printf(“Highest Average of %d was Scored by %s \n”, highest_avg, name);
    printf(“Overall Average of All Bowlers = %d\n”, overall_avg);
    return 0;
    Last edited by uural4792; 10-13-2011 at 10:12 PM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Please cut to the chase, and tell us WHAT is not working on your program, and WHAT have you tried to fix it?

    Are you getting any compiler errors, or warnings? What is the bad output?

  3. #3
    Registered User
    Join Date
    Oct 2011
    I'm getting one warning which is saying "char format, different type arg (arg2)" which I don't really understand. We learned about argc and argv today in class and I still don't understand it fully.

    It also says that there is a implicit declaration of strcpy (??)

  4. #4
    Registered User
    Join Date
    Jun 2005
    You have thrown together a number of things you don't really understand, and then wonder why it doesn't work.

    Try doing things incrementally. For example, get the code for reading data in working first. Then work out how to use the for loop to do something, and then look at the if blocks.

    In other words, get one small thing working right before trying to get the next working. Just throwing a few disconnected things together is an effective way to create something that won't work, and anything you do from there will probably just make it work worse.

    Unless you show some hint of working systematically, rather than trying things at random, you can't expect others to help you much.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Join Date
    Aug 2010
    Ontario Canada
    From your sample code...
    #include <string.h> at line 3
    Lose the & on line 16
    Lose the two \n on line 18
    Lines 20 to 28 should be an if() - else if() chain.
    Lines 21, 23, 25, 27 and 29 should be in braces
    On line 38 you need to look up the correct syntax for strcpy()
    Also on line 38 you cannot assign strings across the equals sign in C.

    You need to turn your compiler's warning level up to maximum and then pay attention to everything it reports. The errors and warnings usually contain line numbers, follow each one and fix it. It tells you that stuff for a real good reason.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Complicated database problem
    By Phane in forum C Programming
    Replies: 4
    Last Post: 04-01-2011, 09:45 AM
  2. Probably way too complicated for me.
    By Necrofear in forum Windows Programming
    Replies: 3
    Last Post: 05-21-2006, 05:41 AM
  3. Complicated Memory/Pointer Problem
    By Axpen in forum C Programming
    Replies: 3
    Last Post: 07-29-2004, 01:48 PM
  4. complicated
    By ZakkWylde969 in forum A Brief History of
    Replies: 14
    Last Post: 07-12-2003, 09:15 AM
  5. Nothing complicated, just...
    By SMurf in forum Windows Programming
    Replies: 1
    Last Post: 09-01-2002, 05:59 PM