Error1error C2181: illegal else without matching if. Line 41
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
string zipCode = "";
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.length() != 5)
cout %26lt;%26lt; "The zip code must contain five digits! " %26lt;%26lt; endl;
else
{
beginZipCode = zipCode.substr(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;
Help with C++ please!! i am getting this error and don't know how to fix it:?
You're missing some brackets. Try this:
#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
string zipCode = "";
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.length() != 5)
cout %26lt;%26lt; "The zip code must contain five digits! " %26lt;%26lt; endl;
else
{
beginZipCode = zipCode.substr(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;
}
cout %26lt;%26lt; "Enter a zip code: "%26lt;%26lt;endl;
cin %26gt;%26gt;zipCode;
}
return 0;
} //end of main function
Reply:Only one } ???
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment