Home > OS >  how do i fix " is a variable but is used like a type [New folder] "
how do i fix " is a variable but is used like a type [New folder] "

Time:06-29

i recently started learning c# and i want the user to input a two digit numbers and than the console to multiply the two digit number (first digit * second digit) and than the console to find out if its an even or an odd number,

//user type question

int first1;
int second2;

Console.WriteLine("type a digit");
first1 = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("type a second digit");
second2 = Convert.ToInt32(Console.ReadLine());

Console.ReadKey();

//the answer

int result = multiplied(first1, second2);
Console.WriteLine("the result is "   result);

if (result % 2 == 0)
{
    Console.WriteLine("it is an even number");
}

else
{
    Console.WriteLine("it is an odd number");
}

//machine

int multiplied (first1, second2) 
{

    int result = first1 * second2;

    return result;
    
} ```

the errors are

Argument 1: cannot convert from 'int' to 'first1' [New folder]
Argument 2: cannot convert from 'int' to 'second2' [New folder]
'first1' is a variable but is used like a type [New folder]
Identifier expected [New folder]
'second2' is a variable but is used like a type [New folder]
Identifier expected [New folder]

CodePudding user response:

Your multiplied function is missing the parameter types

CodePudding user response:

You need to explicitly state the data types of parameters which you pass in a method. So you need to change your code like this:

int multiplied (int first1, int second2) 
{

    int result = first1 * second2;

    return result;

}
  • Related