473,396 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

help! :(

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 <stdio.h>
#include <stdlib.h>

#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
20 2440

"honeygrl33" <gi*************@aol.com> 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
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:
/*
*/
<<clip>> ----------------------------
i need the printresults...
lowest, highest, and average... heeeeelp! please? i will owe u one!!


/* Here is my implementation: */
#include <stdio.h>
#include <stdlib.h>

#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
AIM me!! girliegirl4ever
thanks so much

Nov 14 '05 #4
AIM me!! girliegirl4ever
thanks so much

Nov 14 '05 #5
oh my you are a lifesaver, thnak you!!!

Nov 14 '05 #6
"honeygrl33" <gi*************@aol.com> 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

"Tatu Portin" <ax****@mbnet.fi> 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:
/*
*/

<<clip>>
----------------------------
i need the printresults...
lowest, highest, and average... heeeeelp! please? i will owe u one!!


/* Here is my implementation: */
#include <stdio.h>
#include <stdlib.h>

#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
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

"honeygrl33" <gi*************@aol.com> 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
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
"Ben Pfaff" <bl*@cs.stanford.edu> 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
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 <stdio.h>
#include <stdlib.h>

#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
That still has the endless loop, just tried it..... why wont tyhe loop
end?

Nov 14 '05 #14
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
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
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
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

"honeygrl33" <gi*************@aol.com> 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
ok.. gotcha! :)

Nov 14 '05 #20
On 6 Dec 2004 16:11:04 -0800, in comp.lang.c , "honeygrl33"
<gi*************@aol.com> 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 <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
Nov 14 '05 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.