Answers for "saving variables in a string"

0

saving variables in a string

#include <iostream>
#include <string>

using namespace std;
// you need to tell the compiler where the entry point is 
int main()
{
    string first;
    string middle;  // here you have your variables declared
    string last;

    cout<<"Enter your first name: ";
    getline(cin,first);  // this works and you can also get inpout like  cin>>first;
    cout<<"Enter your middle name: ";
    getline(cin,middle);
    cout<<"Enter your last name: ";
    getline(cin,last);

    first="Henry";  //here you have the same variable declared twice
    middle="Louis"; // either get rid of all strings and make it   middle = "Louis"
     last="Aaron";  //or declare different variables like first1, or something else

    string name;
    name = first + " " + middle + " " + last;
    cout << "Name is: " << name << endl;
// dont forget 
    return 0;
}  //everything else should compile, but I'm not debugging it for you
Posted by: Guest on June-17-2021

Browse Popular Code Answers by Language