Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
C

CounterClockWise

@CounterClockWise
About
Posts
2
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Program keeps looping [Solved]
    C CounterClockWise

    That worked perfectly. Thank you so much! Thanks, Carla

    C / C++ / MFC help c++ question

  • Program keeps looping [Solved]
    C CounterClockWise

    I'm new to C++ programming and also new to posting on forums. I'm sorry if I don't enter this correctly for my first post. I am trying to create a program that will display a predetermined shipping charge for 2 zip codes. Program should send error messages if the zip code entered is not 5 digits long, not all 5 numbers, or does not begin with 605 or 606. Below is the code I have written so far. Sentinel value of -1 should end the program. The messages seem to be correct when I enter test data but it keeps looping the same message repeatedly and I have to close the program to stop it. Can anyone tell me what I've done wrong? #include #include #include using namespace std; //function prototype char verifyNumbers(string); int main () { //declare variables string zip = " "; char isAllNumbers = ' '; const string invalid_length = "Invalid length"; const string not_all_numbers = "Not all numbers"; const string invalid_shipping = "Zip code is not valid for shipping charges"; //get input (zip code) cout << "Enter 5 digit zip code (-1 to end): "; getline(cin, zip); //verify input while (zip != "-1") { if (zip.length() == 5) { isAllNumbers = verifyNumbers(zip); if (isAllNumbers == 'Y') { if (zip.find ("605", 0) == 0 || zip.find ("606", 0) == 0) { if (zip.find("605", 0) == 0) { cout << "Shipping is $25" << endl; } else cout << "Shipping is $30" << endl; //end if } else cout << invalid_shipping << endl; //end if } else cout << not_all_numbers << endl << endl; //end if } else cout << invalid_length << endl << endl; //end if cout << "Enter 5 digit zip code (-1 to end): "; getline(cin, zip); } //end while //calculate shipping charges //display output } //end of main function //*****function definitions***** char verifyNumbers(string zip) //determine if each character is a number { //declare variables string currentChar = ""; int x = 0; char isNumber = 'Y'; //determine if characters are all numbers while (x < 5 && isNumber == 'Y') { currentChar = zip.substr(x, 1); if (currentChar >= "0" && currentChar <= "9") x += 1; else isNumber = 'N'; //end if }//end while return isNumber; } //end of verifyNubmers function I really appreciate any help I can get! Thank you! Carla

    C / C++ / MFC help c++ question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups