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!! 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
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 */
AIM me!! girliegirl4ever
thanks so much
AIM me!! girliegirl4ever
thanks so much
oh my you are a lifesaver, thnak you!!!
"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_
"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
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?
"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
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.
"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
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 */
That still has the endless loop, just tried it..... why wont tyhe loop
end?
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.
i created a new file w/ur code -- still looped over and over! youre
awesome thanks for all the help, youre so nice!
i created a new file w/ur code -- still looped over and over! youre
awesome thanks for all the help, youre so nice!
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%)
"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
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> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |