By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 424,660 Members | 1,037 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

# help! :(

 P: n/a i accidentially erased something someone helped me write and i am soooo in trouble if i dont fix this, i really need the help!!!!! heres what i have: /* */ #include #include #define SIZE 12 void printResults (char months[][15], double sales[]); void storeSales (char months[][15], double sales[]); int main ( void ) { system ("clear"); int i; double sales[ SIZE ]; char months [SIZE][15] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; for (i = 0; i < SIZE; i++) { printf("%-9s: %9.2f/n", months[ i ], sales[ i ]); } storeSales (months, sales); printResults (months, sales); return 0; } void storeSales ( char months[][15], double sales[] ) { int i = 0; for ( i = 0; i < SIZE; i++ ) { do { printf("Enter the store's sales for the month of %s:", months[ i ]); scanf( "9.2%lf", &sales [ i ]); printf("\n"); } while ((sales[ i ] < 0.00 ) || ( sales[ i ] > 100000.00)); } } ---------------------------- i need the printresults... lowest, highest, and average... heeeeelp! please? i will owe u one!! Nov 14 '05 #1
Share this Question
20 Replies

 P: n/a "honeygrl33" wrote in message news:11**********************@c13g2000cwb.googlegr oups.com... heres what i have: #define SIZE 12 void printResults (char months[][15], double sales[]); void storeSales (char months[][15], double sales[]); ---------------------------- i need the printresults... lowest, highest, and average... heeeeelp! please? i will owe u one!! You need to traverse your sales array and find the average, which is the total sum divided by the number of elements. You'll want a "for" loop for this. While you're traversing the array, you'll also want to capture the lowest and highest values. You'll need 2 "if" statements for this. Are you on-track so far? karl m Nov 14 '05 #2

 P: n/a honeygrl33 wrote: i accidentially erased something someone helped me write and i am soooo in trouble if i dont fix this, i really need the help!!!!! heres what i have: /* */ <> ---------------------------- i need the printresults... lowest, highest, and average... heeeeelp! please? i will owe u one!! /* Here is my implementation: */ #include #include #define SIZE 12 void printResults (char months[][15], double sales[]); void storeSales (char months[][15], double sales[]); /* Problems with 'storeSales', you should fix them.*/ int main ( void ) { system ("clear"); int i; double sales[ SIZE ]; char months [SIZE][15] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; for (i = 0; i < SIZE; i++) { printf("%-9s: %9.2f\n", months[ i ], sales[ i ]); } storeSales (months, sales); printResults (months, sales); return 0; } void storeSales ( char months[][15], double sales[] ) { int i = 0; for ( i = 0; i < SIZE; i++ ) { do { printf("Enter the store's sales for the month of %s:", months[ i ]); scanf( "9.2%lf", &sales [ i ]); printf("\n"); } while ((sales[ i ] < 0.00 ) || ( sales[ i ] > 100000.00)); } } void printResults (char months[][15], double sales[]) { int i; double lowest = 0.0, highest = 0.0, average = 0.0; for (i = 0 ; i < SIZE ; i++) average = average + (sales[i] / SIZE); printf ("Average: %lf\n", average); lowest = sales[0]; for (i = 0 ; i < SIZE ; i++) { if (lowest > sales[i]) { lowest = sales[i]; } } printf ("Lowest: %lf\n", lowest); highest = sales[0]; for (i = 0 ; i < SIZE ; i++) { if (highest < sales[i]) { highest = sales[i]; } } printf ("Highest: %lf\n", highest); } /* The End */ Nov 14 '05 #3

 P: n/a AIM me!! girliegirl4ever thanks so much Nov 14 '05 #4

 P: n/a AIM me!! girliegirl4ever thanks so much Nov 14 '05 #5

 P: n/a oh my you are a lifesaver, thnak you!!! Nov 14 '05 #6

 P: n/a "honeygrl33" writes: AIM me!! girliegirl4ever thanks so much Cut it out with the multiple posts. Usenet is not chat. -- "When in doubt, treat ``feature'' as a pejorative. (Think of a hundred-bladed Swiss army knife.)" --Kernighan and Plauger, _Software Tools_ Nov 14 '05 #7

 P: n/a "Tatu Portin" wrote in message news:PF**************@read3.inet.fi... honeygrl33 wrote: i accidentially erased something someone helped me write and i am soooo in trouble if i dont fix this, i really need the help!!!!! heres what i have: /* */ <> ---------------------------- i need the printresults... lowest, highest, and average... heeeeelp! please? i will owe u one!! /* Here is my implementation: */ #include #include #define SIZE 12 void printResults (char months[][15], double sales[]); void storeSales (char months[][15], double sales[]); /* Problems with 'storeSales', you should fix them.*/ int main ( void ) { system ("clear"); int i; double sales[ SIZE ]; char months [SIZE][15] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; for (i = 0; i < SIZE; i++) { printf("%-9s: %9.2f\n", months[ i ], sales[ i ]); } storeSales (months, sales); printResults (months, sales); return 0; } Why are you printing the sales array without INSTANTIATING any values in it? What do you expect beyond GIGO? karl m Nov 14 '05 #8

 P: n/a I really wish I could tell you... also, I really wish I knew what that meant.. my friend said it meant I didn't put anything in the values? Nov 14 '05 #9

 P: n/a "honeygrl33" wrote in message news:11**********************@f14g2000cwb.googlegr oups.com... I really wish I could tell you... also, I really wish I knew what that meant.. my friend said it meant I didn't put anything in the values? So it's premature to output values from sales at that point in the program's execution. Do you think the "print loop" is needed at all, and if so where does it belong. karl m Nov 14 '05 #10

 P: n/a honeygrl33 wrote: I really wish I could tell you... also, I really wish I knew what that meant.. my friend said it meant I didn't put anything in the values? If you do not initialize variables, they can have any value. For example int apples; printf ("%d", apples); would print out "-135468" or any other number. but int apples = 5; printf ("%d", apples); would print out "5". Same holds for arrays. You can initialize arrays with zeros with code: #define DAYS 30 int i; int tomatoes_per_day[30]; for (i = 0 ; i < DAYS ; i++) tomatoes_per_day[i] = 0; Now every value in array 'tomatoes_per_day' has value which is zero. Nov 14 '05 #11

 P: n/a "Ben Pfaff" wrote in message news:87************@benpfaff.org... Cut it out with the multiple posts. Usenet is not chat. I think that usenet is suffering a feed-back loop. There are many posts coming up dups in my newsreader right now. karl m Nov 14 '05 #12

 P: n/a Here is the whole code working. If you are using gcc to compile your programs, you may use the line 'gcc -Wall -pedantic a.c' where 'a.c' is the source file. This prints a lot warnings if something is wrong. /* Start Of File */ #include #include #define SIZE 12 void printResults (char months[][15], double sales[]); void storeSales (char months[][15], double sales[]); int main ( void ) { double sales[ SIZE ]; char months [SIZE][15] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; system ("clear"); storeSales (months, sales); printResults (months, sales); return 0; } void storeSales ( char months[][15], double sales[] ) { int i = 0; for ( i = 0; i < SIZE; i++ ) { do { printf("Enter the store's sales for the month of %s:", months[ i ]); scanf( "%lf", &sales[i]); /* scanf: "%lf" for double*/ /* User sees if he or she has entered the correct * value. */ printf("%f\n", sales[i]); /* printf: "%f" for double*/ } while ((sales[ i ] < 0.00 ) || ( sales[ i ] > 100000.00)); } } void printResults (char months[][15], double sales[]) { int i; double lowest = 0.0, highest = 0.0, average = 0.0; for (i = 0; i < SIZE; i++) { printf("%-9s: %9.2f\n", months[ i ], sales[ i ]); } for (i = 0 ; i < SIZE ; i++) average = average + (sales[i] / SIZE); printf ("Average: %f\n", average); lowest = sales[0]; for (i = 0 ; i < SIZE ; i++) { if (lowest > sales[i]) { lowest = sales[i]; } } printf ("Lowest: %f\n", lowest); highest = sales[0]; for (i = 0 ; i < SIZE ; i++) { if (highest < sales[i]) { highest = sales[i]; } } printf ("Highest: %f\n", highest); } /* End Of File */ Nov 14 '05 #13

 P: n/a That still has the endless loop, just tried it..... why wont tyhe loop end? Nov 14 '05 #14

 P: n/a honeygrl33 wrote: That still has the endless loop, just tried it..... why wont tyhe loop end? while ((sales[ i ] < 0.00 ) || ( sales[ i ] > 100000.00)); You have to enter a number that is between 0.00 and 100000.00. If it still does not work, I usually play around with the code, e.g. try removing the do { /* ... */ } while (/* ... */) loop. Also you may try copy & paste my code and compile it. You may have a typing error if you have copied the examples presented by hand. Nov 14 '05 #15

 P: n/a i created a new file w/ur code -- still looped over and over! youre awesome thanks for all the help, youre so nice! Nov 14 '05 #16

 P: n/a i created a new file w/ur code -- still looped over and over! youre awesome thanks for all the help, youre so nice! Nov 14 '05 #17

 P: n/a Enter the store's sales for the month of January:0.000000 Enter the store's sales for the month of January:0.000000 Enter the store's sales for the month of January:0.000000 Enter the store's sales for the month of January:0.000000 Enter the store's sales for the month of January:0.000000 Enter the store's sales for the month of January:0.000000 Enter the store's sales for the month of January:0.000000 Enter the store's sales for the month of January:0.000000 Enter the store's sales for the month of January:0.000000 Enter the store's sales for the month of January:0.000000 Enter the store's sales for the month of January:0.000000 That's what yours does, and mine does too -- I fixed discrepancies (ie: if it says lf% instead of f%) Nov 14 '05 #18

 P: n/a "honeygrl33" wrote in message news:11*********************@f14g2000cwb.googlegro ups.com... i created a new file w/ur code -- still looped over and over! youre awesome thanks for all the help, youre so nice! Pay no attention to the "error" message that googlegroups is giving you about "not posting", or "queueing" your messages -- it's causing duplicate postings. karl m Nov 14 '05 #19

 P: n/a ok.. gotcha! :) Nov 14 '05 #20

 P: n/a On 6 Dec 2004 16:11:04 -0800, in comp.lang.c , "honeygrl33" wrote: That's what yours does, and mine does too -- I fixed discrepancies (ie:if it says lf% instead of f%) Firstly can you LEAVE SOME CONTEXT in your posts (like I did above). Several people posted code ideas, there's no way to know whose code you refer to. By leaving a few lines of relevant context, you allow people to see what you're referring to. Secondly, if the discrepancy you refer to is the %lf in scanf vs the %f in printf, PLEASE read a C book, or at least your help files / manual - this is NOT a discrepancy. -- Mark McIntyre CLC FAQ CLC readme: Nov 14 '05 #21

### This discussion thread is closed

Replies have been disabled for this discussion.