New Programmer in College
Im taking a class with a book called C by Dissection, Pretty good book so far no complaints. I am just having problems with a lil bit of the code and understanding the the if statements. Basically what I need it to say is :
************************************************** ************************************************** ****
Adjust your program to allow for cases where the user either breaks even or loses money. If the user breaks even, print out the following statement:
You have broken even from selling goldfish.
If the user loses money, print out a statement of the following format:
Your loss from selling goldfish is $XX.XX.
************************************************** ************************************************** ****
Here is a sample of my code. Any suggestions would be greatly appreciated as I am new to the programming world and am VERY LOST:
Code:
#include <stdio.h>
int main(void)
{
float length1,width1,height1,area,volume,total,sum1,sum2,finalsum,revenue,profit;
int fishsum;
#define PRICE1 .02
#define PRICE2 .005
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);
}
else
{
if (profit < 0)
{
printf("\nYour profit is $%.2f. \n", profit);
}
}
return 0;
}