I just started a higher education course and one of the things we were sent off to do as independent study was to go on W3Schools and work through part of their C# tutorials. I ended up making this kind of registration console app, and I’ve run into an issue where I THINK it’s telling me that it can’t find the values from the variables in a different method.
It’s not actually going to be used for anything, but I think this might be me actually just misunderstanding how the methods work, so I thought it was probably worth coming here. I’m sorry if this is a really simple solution ;-;
The full error in VS Code was “There is no argument given that corresponds to the required parameter ‘username’ of ‘Registration.Confirm(int, int)’ (CS7036) [Ln 60, Col 13]’ and it also occurs at Ln 77, Col 17
And Here’s the code:
using System;
using System.ComponentModel;
using System.Threading;
using System.Globalization;
using System.Reflection.PortableExecutable;
using System.Reflection.Metadata.Ecma335;
namespace TestRegister
{
public class Registration
{
public static void Main(string[] args)
{
var today = DateTime.Today;
var myAge = today.Year - 2008;
// this is a comment. this code prints to the console
var myName = "My Name "; // this usually has my actual name but im removing it on public forums :)
Console.WriteLine("Hello World!");
Console.WriteLine("This is a test program!");
Console.WriteLine("281 plus 1412 equals:");
Console.WriteLine(281 + 1412);
Console.WriteLine("This test program was written by:");
Console.WriteLine(myName);
Console.WriteLine("And my age is:");
Console.WriteLine(myAge);
EnterUsername();
/* this is the beginnning of a Multi-line comment
and this is the end of a multi-line comment */
}
public static void EnterUsername()
{
var maximumUserLength = 15;
Console.WriteLine("Enter your Username:");
string username = Console.ReadLine();
if(username.Length > maximumUserLength)
{
Console.WriteLine("Usernames can only be up to 15 characters long. Please try again with a shorter username.");
EnterUsername();
}
else;
EnterAge();
}
public static void EnterAge()
{
var maximumAge = 85;
Console.WriteLine("Enter your age:");
int age = Convert.ToInt32(Console.ReadLine());
if(age > maximumAge)
{
Console.WriteLine("Sorry, you are older than our age limit.");
EnterUsername();
}
else;
Confirm();
}
public static void Confirm(int username, int userAge)
{
Console.WriteLine("Confirm: Your chosen Username is: " + username + " and your current age is: " + userAge + ". (Y/N)");
string ConfirmDetails = Convert.ToString(Console.ReadLine());
if(ConfirmDetails.Contains("y"))
{
Console.WriteLine("Thank you for the information. You have been registered.");
}
else if(ConfirmDetails.Contains("n"))
EnterUsername();
else;
Console.WriteLine("Invalid character.");
Confirm();
}
}
}
`
I’ve been staring at this trying things from the examples on W3Schools as well as looking up the problem online but I haven’t been able to fix it after about 2 hours. The only thing I can think of doing other than coming here was to ask an AI but I’m not sure I want to start relying on that already. Thanks.
SomeFurredNerd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.