-
April 15th, 2013, 08:35 PM
#1
concatenation of strings when entering city, state and zip code
I have written my code, but can't seem to figure out why it doesn't enter the while loop and start asking for Input. Any insight would be greatly appreciated. Just need a direction to go in.
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
//declare variables
string cityName = "";
string stateName = "";
string zipCode = "";
string fullAddress = "";
string loopValue = "";
cout << "Enter -1 to end or press enter to key in a date: ";
getline(cin, loopValue);
while (loopValue != "-1");
{
cout << "Enter city: ";
getline(cin, cityName);
cout << "Enter state: ";
getline(cin, stateName);
cout << "Enter zip code: ";
getline(cin, zipCode);
fullAddress = cityName + ", " + stateName + " " + zipCode;
cout << fullAddress << endl;
cout << "Enter -1 to end or press enter to key in a date: ";
getline(cin, loopValue);
}
cin.get();
return 0;
} //end of main function
-
April 15th, 2013, 08:45 PM
#2
Re: concatenation of strings when entering city, state and zip code
Took all of 2 or 3 seconds to figure out using the debugger.
while (loopValue != "-1");
Typically you'd use an int or a bool to control a loop rather than a string, but that's not your problem here, just a good habit.
-
April 15th, 2013, 08:59 PM
#3
Re: concatenation of strings when entering city, state and zip code
Lol something so simple...thank you so much. I must be getting tired.
-
April 16th, 2013, 03:50 PM
#4
Re: concatenation of strings when entering city, state and zip code
Originally Posted by f0rumh4x
Code:
string cityName = "";
What is the reason for explicitly initializing string variables with the empty string?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|