The code is complete, but I can\'t find the logic error. Can someone help me fin
ID: 3634811 • Letter: T
Question
The code is complete, but I can't find the logic error. Can someone help me find it?Here is the code:
#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 the 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 fertilizer per square foot is: $"
<< area/cost << endl;
system("pause");
return 0;
}
Explanation / Answer
#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 the 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;
//here is the logical mistake in the below line since The cost of fertilizer per pound is= cost/bagSize
cout << "The cost of the fertilizer per pound is: $"
<< cost/bagSize<< endl;
//here is the logical mistake in the below line since The cost of fertilizer per square foot is= cost/area
cout <<"the cost of fertilizer per square foot is :$"<<cost/area<<endl;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.