I need to make a program that outputs a name based on the users input. For the middle name I'm only supposed to show the middle initial. But the way I have my code written causes an error.
#include<iomanip>
#include<iostream>
#include<string>
using namespace std;
string firstName;
string lastName;
string middleName;
string middleInitial;
int main(){
cout<<"Enter your first Name: "; cin>>firstName;
cout<<"Enter your middle name or initial: "; cin>>middleName;
cout<<"Enter your last name: "; cin>>lastName;
cout<<"Your name is: "<<endl;
for(int i=0; i<middleName.length; i++){
middleInitial = middleName[1];
}
cout<<lastName <<", " <<firstName<<" " <<middleInitial <<endl;
}