taterSALAD
October 3rd, 2009, 06:23 PM
Can someone please explain to me how the transform() function works?
transform(string.begin(), string.end(), string.begin(), function);I know that you use toupper or tolower as the function, but I don't know what exactly goes in the third item of the syntax, the repeated string.begin
He's what my code currently is:
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
using namespace std;
int main()
{
const double TAXRATE = .03;
const double GUNTER_TAXRATE = .0325;
double purchase = 0.0;
string county = "";
double tax = 0.0;
cout << "Purchase price: ";
cin >> purchase;
cin.ignore(100, '\n');
cout << "County: ";
getline(cin, county);
transform(county.begin(), county.end(), county.begin(), toupper);
if ( county == "GUNTER" )
tax = purchase * GUNTER_TAXRATE;
else
tax = purchase * TAXRATE;
// end if
cout << fixed << setprecision(2);
cout << "Tax: " << tax << endl;
// end if
return 0;
}
transform(string.begin(), string.end(), string.begin(), function);I know that you use toupper or tolower as the function, but I don't know what exactly goes in the third item of the syntax, the repeated string.begin
He's what my code currently is:
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
using namespace std;
int main()
{
const double TAXRATE = .03;
const double GUNTER_TAXRATE = .0325;
double purchase = 0.0;
string county = "";
double tax = 0.0;
cout << "Purchase price: ";
cin >> purchase;
cin.ignore(100, '\n');
cout << "County: ";
getline(cin, county);
transform(county.begin(), county.end(), county.begin(), toupper);
if ( county == "GUNTER" )
tax = purchase * GUNTER_TAXRATE;
else
tax = purchase * TAXRATE;
// end if
cout << fixed << setprecision(2);
cout << "Tax: " << tax << endl;
// end if
return 0;
}