Hello, I am relatively new to c++ and I need some help figuring out this error code. The error is C2371. The line of code in question is "int cost; " and "double cost; ". What should I do in order to fix the error? Thank you.
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace std;
int main()
{
int cost;
double cost;
double area;
double bagSize;
std::cout << fixed << showpoint << setprecision(2);
std::cout << "Enter the amount of fertelizer, in pounds,"
<< "in one bag:";
std::cin >> bagSize;
std::cout << endl;
std::cout << "Enter the area, in square feet, that can be,"
<< "fertilazed by one bag:";
std ::cin >> area;
std::cout << endl;
std::cout << "The cost of the fertilizer per pound is: $"
<< bagSize / cost << endl;
std::cout << "The cost of fertilizing per square foot is: $"
<< area / cost << endl;
return 0; //End Line
}
You cannot declare two variables with the same name in a function.
1 2
int cost;
double cost;
It also appears that you need to initialize 'cost' with a value. If you don't initialize it, the value will be undefined. double cost = 25.00; // 25.00$