Reputation:
I've just started learning C# and am attempting to create a new line with the "char" variable. I am getting the error "'char' is a 'type' but is used like a 'variable'" on line 42.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Program1
{
class Program
{
// This is where your program starts
static void Main(string[] args)
{
//Prompt user to enter name
Console.WriteLine("Enter your name, please:");
//Read the name entered
string name = Console.ReadLine();
//Greet the user with name and request the hour
Console.WriteLine("Hello " + name + ", enter the current hour:");
//Read the hour entered
string hour = Console.ReadLine();
//Ask the minute
Console.WriteLine("Enter the current minute:");
//Read the minute entered
string minute = Console.ReadLine();
//Subtract hour by 3 to get NY hour
int NYhour;
int NYh = Convert.ToInt32(hour);
NYhour = NYh - 3;
//Verify current time and prompt New York time
Console.WriteLine("If it is " + hour + ":" + minute + " then it must be " + NYhour + ":" + minute + " in New York.");
//Line break
Char ('n'); //<--- error here
//Ask the current temperature in fahrenheit
Console.WriteLine("What is the current temperature in fahrenheit?");
//Read the current fahrenheit temperature
string fahrenheit = Console.ReadLine();
//Ask the NY temperature in fahrenheit.
Console.WriteLine("What is the fahrenheit temperature in New York?");
//Read the NY fahrenheit temperature
string NYfahrenheit = Console.ReadLine();
//Subtract current temperature from NY for difference
int tempDIF;
int fahrenheitCUR = Convert.ToInt32(fahrenheit);
int fahrenheitNY = Convert.ToInt32(NYfahrenheit);
tempDIF = fahrenheitCUR - fahrenheitNY;
double tempDIFC = (tempDIF - 32) * (5.0 / 9.0);
tempDIFC = ((double)((int)(tempDIFC * 100.0))) / 100.0;
//Prompt with fahrenheit temperature currently and in NY then convert to celsius
Console.WriteLine("If it is " + fahrenheit + "° fahrenheit now and " + NYfahrenheit + "° fahrenheit in New York then there is a " + tempDIF + "° fahrenheit difference or a " + tempDIFC + "° celcius difference!");
//Wait for user to acknowledge the results
Console.WriteLine("Press Enter to terminate...");
Console.Read();
}
}
}
What am I doing wrong?
The code is also here: http://pastebin.com/EERPcFAs
Upvotes: 0
Views: 827
Reputation: 632
Saying Char ('n');
is like saying 42;
It isn't actually viable code. You might be trying to say Char aChar = ('n');
and then you have the variable aChar
to use when you need it.
Upvotes: 1
Reputation: 101681
You should use this to line break:
Console.WriteLine()
In C# parentheses using for method calls.So to do this:
Char('n')
You must have a Char
method but you don't. Char is a value type,and can not be using like this as the error said.
Upvotes: 3