getline issue

closed account (G1pE3TCk)
hey all, I am really new to computer programing. I have to take an intro to C++ course in order to graduate. We have recently been introduced to "getline" however, for the assignment my output keeps coming up as blank.

here is my line of code:

#include <iostream>

#include <cmath>

#include <iomanip>

#include <string>

using namespace std;



/**
* <>
*
* @return 0 Indicating successful completion.
*/

int main()

{
//Variables

string fullname1;



cout << "Please enter your name (first and last name order): ";
cin >> fullname1;
cout << "===> Welcome, ";
getline(cin, fullname1);
cout << endl;
cout <<endl;
cout << "Enter a loan amount: ";

return 0;
}


this is what it looks line when the program runs:

Please enter your name (first and last name order): Grace Hopper
===> Welcome,

Enter a loan amount:
RUN FINISHED; exit value 0; real time: 4s; user: 0ms; system: 0ms


as you can see, the name is not showing up after "welcome,"

anyone have an idea where my problem is?

what compiler are you using? -is not a compiler problem but i want to know

Well you have to output the variable fullname1 after or together

cout << "===> Welcome, ";
statement

and use
getline(cin, fullname1);
statement instead of
cin >> fullname1;


why don't you have an amount variable?
Last edited on
Your first few lines should look like this

1
2
3
cout << "Please enter your name (first and last name order): ";
getline(cin, fullname1);
cout << "===> Welcome, " << fullname1;
Topic archived. No new replies allowed.