Reputation: 11
This is a problem in two parts - one before and one after reinstalling Visual Studio 2019.
To set the scene, I am trying to lean programming C# following a course on Udemy, in other words I am a complete beginner.
Part One:
Regardless of what program I attempt to run, using CTRL + F5, from Visual Studio (Microsoft Visual Studio Community 2019 - Version 16.5.5) - I just get at black Console window with no text the first three to four times I press CTRL + F5, then it works on the next try. Once it works it continues to work every time, even if I makes changes to the program.
Press CTRL + F5 -> Black Console, I close console;
Press CTRL + F5 -> Black Console, I close console;
Press CTRL + F5 -> Black Console, I close console;
Press CTRL + F5 -> Black Console, I close console;
Press CTRL + F5 -> works.
After that it works every time.
Write a new program, and I have to go through this again.
What is causing this?
Part Two:
To this someone suggested uninstalling VS, and reinstalling it.
All new projects now are a "Hello World" program and include this line of code Console.WriteLine("Hello World!"); they didn't before
Here is an example of a program that took a few tries to get to run (See part one):
using System;
namespace Exercise4 { class Program { static void Main(string[] args) { const int demeritPrKm = 5; Console.WriteLine("Enter speed limit:"); var speedLimit = Convert.ToInt32(Console.ReadLine());
{
int demeritPoints;
int speedExceedance;
Console.WriteLine("Enter actual speed:");
var actualSpeed = Convert.ToInt32(Console.ReadLine());
if (actualSpeed <= speedLimit && actualSpeed>0)
{
Console.WriteLine("Speed within limits");
}
else
{
demeritPoints = ((actualSpeed - speedLimit) / demeritPrKm);
speedExceedance = (actualSpeed - speedLimit);
Console.WriteLine("Speed limit exceeded by " + speedExceedance + "km/h, Demerit points: " + demeritPoints);
if (demeritPoints > 12)
{
Console.WriteLine("***** LICENSE SUSPENDED *****");
}
else
{
Console.WriteLine("** License OK **");
}
}
}
}
}
}
Upvotes: 1
Views: 496
Reputation: 319
You Don't have the Console.Readkey()
In your codes
try inserting it in the last line of your codes and try building and running again.
Upvotes: 0