### Thread: Simple C Program Help

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2013
Posts
2
Rep Power
0

#### Simple C Program Help

I'm wondering if anyone can help me with this program. This is what I have so far:

#include <stdio.h>
#define GOODROD 10

int main( void )
{
int NormalCount=0; //
int NotmalTotal=0; //
double NormalAverage=0; //
int ShortCount=0; //
int ShortTotal=0; //
double ShortAverage=0; //
int LongCount=0;
int LongTotal=0;
double LongAverage=0;

int rod=1;

while(rod!=0) //
{
printf ("ENTER INTEGER ROD LENGTH: ");
scanf ("%i",&rod);

if(rod==0){break;} //

printf("%2i \n", rod);

if (rod=GOODROD)
{
NormalCount = NormalCount+1;
NormalTotal = NotmalTotal+rod;
}

else if (rod>GOODROD)
{
=long
}

else
{
=shorts
}
}
OverallCount = ShortCount + LongCount + NormalCount;
OverallTotal = ShortTotal + LongTotal + NormalTotal;

NormalAverage = (double) NormalTotal/NormalCount;

printf("statistics:\n");
printf("DESC, NUMBER, TOTAL, AVERAGE");

return0;
}
This is what a sample output should be:

SAMPLE OUTPUT:

Enter an integer number: 99
99
Enter an integer number: 99
99
...
Enter an integer number: 0

Statistics:
Desc Number Total: Average:
Normal 99 9999 999.99
Short 99 9999 999.99
Long 99 9999 999.99
Overall 99 9999 999.99

----PARTIAL SAMPLE OUTPUT:
Long 6 80 13.33
Thanks for any help that anyone can provide. I haven't fully completed it, and have no clue how to yet. Hope I will soon.
2. #### necessary but insufficient alterations recommended.

Where you have
return0;
you most likely intend
return 0;
//Only perfect spellers may
//enter this system.

Where you have
if (rod=GOODROD)
you most likely intend
if (GOODROD == rod)

Where you have
ENTER INTEGER ROD LENGTH
you most likely intend
ENTER INTEGRAL ROD LENGTH
point being that "verb noun noun" is a disagreeable sentence structure. The adjective "INTEGRAL" modifies the noun "ROD LENGTH".
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2013
Posts
2
Rep Power
0
Ok, thanks for that. Here's some info I missed from before:

SAMPLE INPUT:
12
14
10
10
7
18
4
10
12
10
10
12
8
10
10
10
10
9
12
10
0
Do you know where I would put this in the code, if at all? Or would the input be randomized?

Also, under

NormalAverage = (double) NormalTotal/NormalCount;

ShortAverage = (double) ShortTotal/ShortCount;

and

LongAverage = (double) LongTotal/LongCount;
?
4. #### I hate if statements.

Code:
```#include<stdio.h>
#include<string.h>

#define GOODROD 10//who can resist working a program with this definition?

float average(sum, n) {
return sum/(float)n;
}

int main() {
int i, sum[3], count[3], rod, grand_sum = 0, grand_count = 0;
char*format = "%4s\t%7d\t%7d\t%8.2f\n";
memset(sum, 0, sizeof(sum)), memset(count, 0, sizeof(sum));
for (;;) {
fputs("ENTER INTEGER ROD LENGTH: ", stdout);
if ((1 != scanf("%i", &rod)) || (rod < 1)) break;
i = (GOODROD <= rod) + (GOODROD < rod);
++count[i], sum[i] += rod;
}
puts("DESC\tNUMBER\tTOTAL\tAVERAGE");
for (i = 0; i < 3; ++i) {
printf(format,
i*5+"TINY\0GOOD\0LONG",
count[i],
sum[i],
average(sum[i],count[i]));
grand_sum += sum[i], grand_count += count[i];
}
return 0*printf(format,"ALL",grand_count,grand_sum,
average(grand_sum,grand_count));
}```
Last edited by b49P23TIvg; September 10th, 2013 at 09:55 PM. Reason: squeezed to remove scroll bar.