Im having trouble using the while statement for a fishtank program.
Here is what I have so far
Code:
#include <stdio.h>
int main()
{
float length1,width1,height1,area,volume,total,sum1,sum2,finalsum,revenue,profit;
int fishsum,num = 1;
#define PRICE1 .02
#define PRICE2 .005
printf ("\nWould you like to calculate your fishtank profit (1=yes, 0=No)?");
scanf ("%d",&num );
while ( num !=0)
{
printf("\nWhat is the length of your goldfish tank in inches? ");
scanf("%f",&length1);
printf("\nWhat is the width of your goldfish tank in inches? ");
scanf("%f",&width1);
printf("\nWhat is the height of your goldfish tank in inches? ");
scanf("%f",&height1);
area = (length1 * height1 * 2) + (height1 * width1 * 2) + (length1 * width1);
volume = (length1 * width1 * height1);
fishsum = volume / 250;
sum1 = PRICE1 * area;
sum2 = PRICE2 * volume;
finalsum = sum1 + sum2;
revenue = fishsum * 5;
profit = revenue - finalsum;
if (profit < 0)
{
printf("\nYour loss from selling goldfish is $%.2f. \n", profit * -1);
}
else if (profit > 0)
{
printf("\nYour profit is $%.2f. \n", profit);
}
else
{
printf("\nYou broke even!");
}}
printf("\nThank you for using the fish tank program, goodbye!");
}
After typing in the number 1, the program proceeds to ask me for the length, width, and height, and outputs the correct answer.
However, After giving me the output, the program asks me for the length again. What I want the program to do is to ask me if I would like to calculate your fish tank profit. Then I have the option to type 1 for yes and to repeat the process or 0 to end the program.
Please help
Thanks Bronz