I'm in my first CS class and I am having trouble getting this to compile. I have looked over my professor's notes, lectures, and examples but it doesn't seem to matter what I type, its an error. I'm getting 38 errors and there's only 25 lines of code! A lot of the errors don't make any sense, for example, "expected a ;" even though there is already a ';', Or "expected a {" after main even though it is clearly there. As far as I can see, visual studio should at least compile my code. Any help at all is much appreciated!
Step by Step Instructions/Correct Output:
Write a program that produces the following output:
/* OUTPUT
Enter your age: 21
Enter the last name: Lee
Hello Tom Lee. You are 21 years old.
Press any key */
1.) Declare an array named: firstName
The array is a c_string, i.e., it is a null-terminated character array.
The size of the array is 10.
Assign a first name to it when it is declared.
2.) Declare an array named: lastName
The array is a c_string,
The size of the array is 10.
Don’t assign a name to it.
3.) Declare an array named: fullName
The array is a c_string,
The size of the array is 20.
Don’t assign a name to it.
4.) In main():
First ask the user for the age.
Read the age and assign it to a variable.
Then ask the user for the last name.
Read the last name and assign it to lastName.
Assign the first and last names to fullName.
Make sure to include a space between the names.
5.) Call a function named: displayInfo().
- The function should output the full name and age. (see output)
My code:
#include <iostream>
#include <string>
using namespace std;
void displayInfo(char fullName, int age)
int main
{
char firstName[10] = "Bob";
char lastName[10] = { 0 };
char fullName[20] = { 0 };
int age;
cout << "Enter your age: ";
cin >> age;
cout << "\nEnter the last name: ";
cin.getline(lastName, 10);
displayInfo(fullName, age)
strcpy_s(fullName, firstName);
strcat_s(fullName, " ");
strcat_s(fullName, lastName);
strcat_s(fullName, ".");
return 0;
}
displayInfo(char fullName, int age)
{
cout << "Hello " << fullName << "You are " << age << "years old.";
}