Click here to Skip to main content
15,887,776 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWaitForMultipleObjects keeps catching timeout event (RESOLVED) Pin
bkelly1313-Apr-14 11:36
bkelly1313-Apr-14 11:36 
AnswerRe: WaitForMultipleObjects keeps catching timeout event Pin
SoMad13-Apr-14 12:28
professionalSoMad13-Apr-14 12:28 
GeneralRe: WaitForMultipleObjects keeps catching timeout event Pin
bkelly1313-Apr-14 14:03
bkelly1313-Apr-14 14:03 
GeneralRe: WaitForMultipleObjects keeps catching timeout event Pin
SoMad13-Apr-14 14:13
professionalSoMad13-Apr-14 14:13 
QuestionLinking errors Pin
tre412-Apr-14 11:51
tre412-Apr-14 11:51 
AnswerRe: Linking errors Pin
Richard Andrew x6412-Apr-14 15:07
professionalRichard Andrew x6412-Apr-14 15:07 
GeneralRe: Linking errors Pin
tre412-Apr-14 22:18
tre412-Apr-14 22:18 
QuestionProgram keeps looping [Solved] Pin
CounterClockWise11-Apr-14 14:13
CounterClockWise11-Apr-14 14:13 
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 <iostream>
#include <iomanip>
#include <string>
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

-- modified 11-Apr-14 22:40pm.
AnswerRe: Program keeps looping Pin
Richard Andrew x6411-Apr-14 16:26
professionalRichard Andrew x6411-Apr-14 16:26 
GeneralRe: Program keeps looping Pin
CounterClockWise11-Apr-14 16:41
CounterClockWise11-Apr-14 16:41 
QuestionDraw two monitors syncron Pin
_Flaviu10-Apr-14 22:11
_Flaviu10-Apr-14 22:11 
AnswerRe: Draw two monitors syncron Pin
Richard MacCutchan10-Apr-14 22:41
mveRichard MacCutchan10-Apr-14 22:41 
AnswerRe: Draw two monitors syncron Pin
pasztorpisti11-Apr-14 6:17
pasztorpisti11-Apr-14 6:17 
GeneralRe: Draw two monitors syncron Pin
_Flaviu13-Apr-14 22:23
_Flaviu13-Apr-14 22:23 
Question[MFC Desktop Application for enumerating Virtual customized folder and files] Windows 8 Address Bar icon problem Pin
Nirmal K P10-Apr-14 19:39
Nirmal K P10-Apr-14 19:39 
QuestionUse PlaySound api caused memory loading? Pin
cedricvictor10-Apr-14 16:02
cedricvictor10-Apr-14 16:02 
AnswerRe: Use PlaySound api caused memory loading? Pin
Richard Andrew x6410-Apr-14 17:19
professionalRichard Andrew x6410-Apr-14 17:19 
QuestionMS Word Automation - I get so far - now what? Pin
Bryan Anslow10-Apr-14 9:43
Bryan Anslow10-Apr-14 9:43 
AnswerRe: MS Word Automation - I get so far - now what? Pin
Richard MacCutchan10-Apr-14 22:39
mveRichard MacCutchan10-Apr-14 22:39 
SuggestionRe: MS Word Automation - I get so far - now what? Pin
David Crow11-Apr-14 4:40
David Crow11-Apr-14 4:40 
QuestionList And iterator Pin
Hamza Bin Amin10-Apr-14 2:49
Hamza Bin Amin10-Apr-14 2:49 
AnswerRe: List And iterator Pin
Maximilien10-Apr-14 10:21
Maximilien10-Apr-14 10:21 
SuggestionRe: List And iterator Pin
David Crow10-Apr-14 15:49
David Crow10-Apr-14 15:49 
Questionavoiding or skipping Divide by zero showing junk values Pin
manoharbalu10-Apr-14 0:50
manoharbalu10-Apr-14 0:50 
AnswerRe: avoiding or skipping Divide by zero crashes Pin
Heng Xiangzhong10-Apr-14 1:00
Heng Xiangzhong10-Apr-14 1:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.