Calculate shipping charge program

Hi,

The problem was that when you put tn instead of TN in for state, it'll give you the wrong answer. This is the solution to the program according to the book, but it keeps giving me error. I wonder if someone can help me fix these errors.Thanks. Program below.

//Ch5Lab5.cpp
//Dislays a shipping charge

#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::getline;
using std::fixed;
using std::setprecision;
using std::transform;

int main()
{
string stateId = "";
double sale = 0.0;
double shipping = 0.0;

//enter input data
cout << "Two-character state ID: ";
getline(cin, stateId);
transform(stateId.begin(), stateID.end(),
stateId.begin(), toupper);
cout << "Sale amount: ";
cin >> sale;

//calculate shipping charge
shipping = sale * .01;
//add $5 to Tennessee shipments
if (stateId == "TN")
shipping = shipping + 5;
//end if

//display shipping charge
cout << fixed << setprecision(2);
cout << "Shipping: " << shipping << endl;

return 0;
} //end of main function
Last edited on
It works fine for me, using XP and MinGW 3.4.5.

What compiler are you using?
I'm using windows xp with visual studio 2005
I got it, the stateID.end is wrong, it should be stateId.end
Really? I thought that was just a typo and I fixed it.

It shouldn't have compiled otherwise...
Topic archived. No new replies allowed.