Please Scroll Down to See Forums Below
napsgear
genezapharmateuticals
domestic-supply
puritysourcelabs
UGL OZ
UGFREAK
napsgeargenezapharmateuticals domestic-supplypuritysourcelabsUGL OZUGFREAK

I need the "C" programmers help

ConstantChange

New member
I'm trying to find an average using 2 arrays. Seems simple enough. This is the approach I'm using....

for (model=1; model<4; model++)
printf("Average for model %d is %.2f\n", model, (model_sale[model-1])/(total_quanity[model-1]));

It compiles with zero errors, but when I tell the program I'm done entering the information and I want it to compute the average, I get an illegal operations error in DOS. The rest of the program runs fine is I leave the average part out.


Here is the screen output:

Please enter the model that you want to purchase.
1 for professional, 2 for office, and 3 for student model
1

Enter quanity:
25

Would you like to purchase more computers? 1 = Yes 2 = No
2

Average for model 1 is 1160.00



It should compute the average for model 2 and model 3, but the illegal error occurs and I have to shut down DOS shell

Is this a computer based problem or a logic error in my code?

(I can post the whole program if someone wanted to compile it on their computer and see if they get an error)
 
How are the variables model_sale and total_quantity set up, in the context of this average part? It seems like they are being interpreted as scalars instead of arrays.
 
I figured out my problem. If the user decides not to by a model...it's quanity is 0. So I've been trying to divide by zero which everyone knows you can't do.

Now I just have to find a way around that. :fro:
 
i think your basic approach is......well just that, too basic. try this and analyze the output then get back with me.

set your two arrays up like this:

[model = or > 1, model +=+]
2nd input = model<safe> = average of model 2 and 3
model1,2,3,= average % safe.

you should get an average in percent at this point of the procedure then just follow standard DOS and microsoft procedures from that point on. rememer, DOS is not fully capable of intersecting two nomes with the same standard procedure.

let me know.
 
Top Bottom