I'm new here and just started my first class program. It's an input/output assignment and I'm using getline to store the string values since I anticipate whitespace being used. The problem is that in the console, the code doesn't allow me to input anything for my favorite city, leaving it blank.

#include <iostream>
#include <string>

using namespace std;

int main()
int userAgeMnths;
float userHeight;
char one, two, three;
string userName, gNumber, favCity;

    cout << "Enter your name: ";
    cout << endl << "Enter your G-Number: ";
    cout << endl << "Enter your height in inches: ";
    cin >> userHeight;
    cout << endl << "Enter your age in months: ";
    cin >> userAgeMnths;
    cout << endl << "Enter three characters: ";
    cin >> one >> two >> three;
    cout << endl << "Enter your favorite city: ";

    cout << endl << endl << userName << ", " << gNumber << endl << endl;
    cout << three << two << one << endl << endl;
    cout << favCity.length() << endl << endl;

    return 0;

Heres my output:

Enter your name: Wireboy guy

Enter your G-Number: g111111111111111

Enter your height in inches: 99999

Enter your age in months: 99

Enter three characters: abc

Enter your favorite city:

Wireboy guy, g111111111111111



This article has been dead for over six months. Start a new discussion instead.