#include "StdAfx.h"
#include <iostream>
#include <string>
#include <sstream>
usingnamespace std;
int main()
{
string Location;
int Gas = 100;
cout << "Type where you want to go.\n>";
getline(cin, Location);
Gas = Gas - 10;
while(Gas > 0)
{
cout << "You are now at " << Location << ", type where you want to go next.\n>";
cin >> Location;
Gas = Gas - 10;
}
if(Gas <=0)
{
cout << "You ran out of gas!\n";
system("PAUSE");
return 0;
}
}
As firedraco said. You get the trailing '\n' added on your string which makes those odd spaces.
No i think the reason why it makes new lines is because "cin >> Location" only stores 1 word which make 2 entries when you inputed "(1)your (2)house"and by use of getline() as what firedraco has said, those 2 or more words will be stored at only 1 string.