I was asked:
Write a program that calculates the cost of painting a room. Ask the user for the number of square feet of surface to be painted. Given that a one gallon can of paint covers 300 square feet and costs $35, calculate the number of gallons required and the total cost of the paint needed. Print the results to the screen ini a well-formated display. (Careful -- can only buy whole gallons of paint.)
#include <iostream>
#include <math.h>
usingnamespace std;
int main()
{
//First, the variables
int can_area = 300; //300 square feet per can
int can_cost = 35; //The cost of 1 can
float paint_area;
int cans = ceil(paint_area/can_area); //This is the number of cans needed.
int cost = can_cost*cans; //The cost is the cost of each, multiplied by all cans.
//Now we'll ask the user for the total area:
cout << "What is the area in square feet? :";
cin >> paint_area; //The user answers with a float or integer number.
cout << "\n";
cout << "\n";
cout << "The number of gallons required is: " << cans;
cout << "\nThe total cost is : " << cost;
return 0;
}
But it gives me a negative number always! What did I do wrong?
#include <iostream>
#include <math.h>
usingnamespace std;
int main()
{
//Now we'll ask the user for the total area:
cout << "What is the area in square feet? :";
cin >> paint_area; //The user answers with a float or integer number.
//First, the variables
int can_area = 300; //300 square feet per can
int can_cost = 35; //The cost of 1 can
float paint_area;
int cans = ceil(paint_area/can_area); //This is the number of cans needed.
int cost = can_cost*cans; //The cost is the cost of each, multiplied by all cans.
cout << "\n";
cout << "\n";
cout << "The number of gallons required is: " << cans;
cout << "\nThe total cost is : " << cost;
return 0;
}