- #1
rezeew
- 1,257
- 0
In our C++ class, we're learning to use functions. In this problem I am working on is to use 4 functions: 3 functions to get your first name, last name, middle initial, and one function to display the your full name.
I wrote the program, but can't get it to run. I've looked over it several times and I don't see where I went wrong. Can anyone see where the error is?
Oh, I wrote it using Visual C++ 2008 Express Ed.#include <iostream>
#include <string>
using namespace std;
string GetFirstName();
string GetLastName();
char GetMiddleInitial();
void DisplayFullName(string firstName, string lastName, char middleInitial);
int main()
{
string firstName;
string lastName;
char middleInitial;
firstName = GetFirstName();
lastName = GetLastName();
middleInitial = GetMiddleInitial();
DisplayFullName(firstName, lastName, middleInitial);
system("pause");
return 0;
}
string GetFirstName()
{
string firstName;
cout << "Enter your first name: ";
cin >> firstName;
return firstName;
}
string GetLastName()
{
string lastName;
cout << "Enter your last name: ";
cin >> lastName;
return lastName;
}
char GetMiddleInitial()
{
char middleInitial;
cout << "Enter your middle Initial: ";
cin >> middleInitial;
return middleInitial;
}
void DisplayFullName(string firstName, string lastName, char middleInitial)
{
cout << "Your full name is " << firstName << " "
<< middleInitial << ". "
<< lastName << ".";
}
I wrote the program, but can't get it to run. I've looked over it several times and I don't see where I went wrong. Can anyone see where the error is?
Oh, I wrote it using Visual C++ 2008 Express Ed.#include <iostream>
#include <string>
using namespace std;
string GetFirstName();
string GetLastName();
char GetMiddleInitial();
void DisplayFullName(string firstName, string lastName, char middleInitial);
int main()
{
string firstName;
string lastName;
char middleInitial;
firstName = GetFirstName();
lastName = GetLastName();
middleInitial = GetMiddleInitial();
DisplayFullName(firstName, lastName, middleInitial);
system("pause");
return 0;
}
string GetFirstName()
{
string firstName;
cout << "Enter your first name: ";
cin >> firstName;
return firstName;
}
string GetLastName()
{
string lastName;
cout << "Enter your last name: ";
cin >> lastName;
return lastName;
}
char GetMiddleInitial()
{
char middleInitial;
cout << "Enter your middle Initial: ";
cin >> middleInitial;
return middleInitial;
}
void DisplayFullName(string firstName, string lastName, char middleInitial)
{
cout << "Your full name is " << firstName << " "
<< middleInitial << ". "
<< lastName << ".";
}