# Thread: A bit more complicated problem

1. ## 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!

Code:
```#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;
else
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;
}```

2. 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. 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. 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.

5. 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