Click here to Skip to main content
15,746,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It's saying that the namespace for, "visitor" and "person" is not found. I'm stuck. Do I have to declare both as strings? My Assignment was to

Create a class called “Person” that has the following public member variables:
 Age (int)
 FirstName (string)
 LastName (string)
 Spouse (Person)
The Person class should also have the following public static variable:
 SumOfAllAges (double)
The Person class should also have the following public methods:
 GetFullName (string)
 PrintNameAndAge (void)
In your main program, you will declare two variables of type Person named “p1” and “p2”.
Ask the user to provide you with the name, age, and marital status of both individuals.
Also, ask for the first name and age of their spouses.
While you are doing this, keep track of the sum of all ages in the static variable you made.
You can assume the spouse automatically gets the same last name as the individual.
Don’t forget to set the “Spouse” variable to the appropriate value for all four people.
After you have collected this information:
 Invoke “PrintNameAndAge()” on each of the four people.
 Print out the single average age of the people. (SumOfAllAges / 4)
You may only have 2 “Person” type variables local to the Main Program. (p1 and p2)
The spouses must be referenced through the “p1.Spouse” and “p2.Spouse” variables.


What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
public class Program
public static void Main(string[] args)
Person p1 = new vistor();
System.Console.WriteLine("What's your first name?");
p1.fName = System.Console.ReadLine();
System.Console.WriteLine("Now tell me your last name.");
p1.lName = System.Console.ReadLine();
System.Console.WriteLine("Please tell me your age now.");
p1.Age = int.Parse(System.Console.ReadLine());
p1.Lover = new vistor();
Person.TotalofAllAges + Person.TotalofAllAges + p1.Age;
System.Console.WriteLine("What's your lover's name?");
p1.Lover.fName = System.Console.ReadLine();
p1.Lover.lName = p1.lName;
System.Console.WriteLine("What's their age?");
p1.Lover.age = int.Parse(System.Console.Readline());
p1.Lover.Lover = p1;
Person.TotalofAllAges = Person.TotalofAllAges + p1.Lover.Age;
Console.WriteLine("Press P to go on");
Updated 2-Dec-18 11:00am

1 solution

Basically, it doesn't know what you are looking for, but it can't find it - so it assumes it's a namespace and reports the error as a namespace problem.
But it isn't - it's that you haven't followed instructions. Read your homework again, and pay attention to the bit where it says
Create a class called “Person” that has the following public member variables ...

Hint: the operative word is "create".
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900