I am a beginning programmer. I am doing a program for class and keep getting error codes C2039, C2873, and C3861 all having to do with setprecision. I am using #include <iomanip>. I have tried rearranging everything and searching the web but still cannot figure out the problem. The code is below. Can anyone help me?
Thanks
Regina
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using std::fixed;
#include "Program3_Wages.h" // include definition of class Wages from Wages.h
// function to calculate wages
void Wages::calculateWages()
{
double hours; // total hours worked
double rate; // hourly pay rate
double salary; // gross pay
// processing phase
// get first employee's hours worked
cout << "Enter hours worked (-1 to end): ";
cin >> hours;
// set floating-point number format
cout << fixed << setprecision( 2 );
// place your while loop here
// loop until sentinel value read from user
while ( hours != -1 ) // while hours are not -1
{
// get double rate
cout << "Enter hourly pay rate: "; // prompt for input
cin >> rate; // input next hourly pay rate
salary = hours * rate; // determines gross pay
I am not sure this is what you mean, but I used win32concsole application. Here is the header file and second source file that was provided for me.
// Program #3 Assignment #4 Object Interface: Program3_Wages.h
// Definition of class Wages that calculates wages.
// Member functions are defined in Program3_Wages.cpp
// (Interface separate from implementation!)
// Wages class definition
class Wages
{
public:
void calculateWages(); // function to calculate wages
// Note: Expecting no arguments (values) coming in
// and no value returned to caller
}; // end class Wages
// Program #3 Assignment #4 Solution: Program3_Client.cpp
// Create Wages object and invoke its calculateWages function.
#include "Program3_Wages.h" // include definition of class Wages from Program3_Wages.h
int main()
{
Wages myWages; // create Wages object myWages
myWages.calculateWages(); // call it's calculateWages function (Note: No arguments sent, and no value to be returned!)
you haven't included the <iomanip> header which is what contains the setPrecision function. Always include the headers where the tool you use is defined. Don't rely on <iostream> including it for you otherwise you will get inconsistent results depending on the compiler. http://cplusplus.com/reference/iostream/manipulators/setprecision/