Sunday, August 2, 2009

C++ help please!! i am getting a buch of errors - i don't how to fix them.i am just a beginer please help me!!

this program should display shipping charge based on the ZIP code entered by the user. this is my code:


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;iomanip%26gt;





using std::cout;


using std::cin;


using std::endl;


using std::string;


using std::setprecision;


using std::fixed;








int main()


{


//declare variables


int zipCode = 0;


string beginZipCode = "";





//get input from user


cout %26lt;%26lt; "Enter a zip code: " %26lt;%26lt; endl;


cin %26gt;%26gt; zipCode;





//calculate and display taxes and net pay


while (zipCode != "x" %26amp;%26amp; zipCode != "X")


{


if (zipCode.lenght() != 5)


cout %26lt;%26lt; "The zip code must contain five digits! " %26lt;%26lt; endl;


else


{


beginZipCode = zipCode.substri(0, 3);





if (beginZipCode == "605")


cout %26lt;%26lt; "Shipping charge: $25.00" %26lt;%26lt;endl;


else if (beginZipCode == "606")


{


cout %26lt;%26lt; "Shipping charge: $30" %26lt;%26lt;endl;


else


cout %26lt;%26lt; "Invalid code!" %26lt;%26lt;endl;


}


}


}

C++ help please!! i am getting a buch of errors - i don't how to fix them.i am just a beginer please help me!!
Without knowing what error you are getting, it is tough to help you out. One error I could spot in the code was in the following line





if (zipCode.lenght() != 5)





there is no method in the String class called lenght. The correct method is length()
Reply:'lenght()' is misspelled
Reply:Couple of errors I spotted:


1) you declared zipCode to be an INT, but you're trying to use it like a String. while(zipCode != "x"... won't work., nor will zipCode.length().





2) Misspelled length()





3) Wrong method: substri() should be substr()





Sometimes it helps to put line numbers so I could have told you which line had the above problems.


No comments:

Post a Comment