homework help

the problem states that the program will run but there are logical errors, im simply too noob to find them can someone help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//Logic errors.
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{  
    double cost;
    double area;
    double bagSize;
    
    cout << fixed << showpoint << setprecision(2);
    
    cout << "Enter the amount of fertilizer, in pounds, "
         << "in one bag: "; 
    cin >> bagSize;
    cout << endl;
    cout << "Enter the cost of the " << bagSize
         << " pound fertilizer bag: ";
    cin >> cost;
    cout << endl;
    
    cout << "Enter the area, in square feet, that can be "
         << "fertilized by one bag: ";
    cin >> area;
    cout << endl;
    cout << "The cost of the fertilizer per pound is: $"
         << bagSize / cost << endl;
    
    cout << "The cost of fertilizing per square foot is: $"
         << area / cost << endl;
    return 0;
}
Your maths is wrong on line 32. And line 29.
Last edited on
Hello CloudFF7,

An observation, if the program compiles and runs that would indicate that there are no logic errors in your code, so the only other possibility would be in the math.

Andy
Hello CloudFF7,

If I corrected the math correctly this should help you understand what the math should be:


Enter the amount of fertilizer, in pounds, in one bag: 50

Enter the cost of the 50.00 pound fertilizer bag: 25

Enter the area, in square feet, that can be fertilized by one bag: 10

The cost of the fertilizer per pound is:    $0.50

The cost of fertilizing per square foot is: $2.50


Hope that helps,

Andy
Let’s say you can buy 2 pounds for 6$.
That means 1 pound = 3$
So you have to do cost/bagsize
13 pounds = 39$
If you want to have 1 pound you have to divide it by 13
13/13 and 39/13
1 pound = 3$
Topic archived. No new replies allowed.