سلام و وقتتون بخیر.
مثال 1:
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("*** Plus Ultra ***");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.WriteLine("\n*** Laptop Temperature Control System ***");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
int errorsCount = 0;
int maxErrors = 5;
int remaining;
bool isCPUTemperatureValid = false;
while (!isCPUTemperatureValid && errorsCount < maxErrors)
{
try
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("\nPlease Enter The CPU Temperature: ");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkYellow;
int inputCPUTemperature = Convert.ToInt32(Console.ReadLine());
Console.ResetColor();
if (inputCPUTemperature >= 25 && inputCPUTemperature <= 95)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine($"\nCPU Temperature Is: ({inputCPUTemperature})C Degrees^^");
Console.ResetColor();
errorsCount = 0;
maxErrors = 5;
bool isGPUTemperatureValid = false;
do
{
try
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("\nPlease Enter The GPU Teperature: ");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkYellow;
int inputGPUTemperature = Convert.ToInt32(Console.ReadLine());
Console.ResetColor();
if (inputGPUTemperature >= 25 && inputGPUTemperature <= 95)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine($"\nGPU Temperature Is: ({inputGPUTemperature})C Degrees^^");
Console.ResetColor();
int fanRotationSpeedCPU;
int fanRotationSpeedGPU;
int coolingTimeCPU = 0;
int coolingTimeGPU = 0;
bool isCPUCoolValid = false;
bool isCPUWasCoolValid = false;
bool isCPUCoolingValid = false;
bool isGPUCoolValid = false;
bool isGPUWasCoolValid = false;
bool isGPUCoolingValid = false;
do
{
if ((inputCPUTemperature >= 25 && inputCPUTemperature <= 35) || (inputGPUTemperature >= 25 && inputGPUTemperature <= 35))
{
if (isCPUCoolValid == false)
{
if (inputCPUTemperature >= 25 && inputCPUTemperature <= 35)
{
if (coolingTimeCPU == 0)
{
isCPUWasCoolValid = true;
isCPUCoolValid = true;
}
else
{
isCPUCoolingValid = true;
isCPUCoolValid = true;
}
}
}
if (isGPUCoolValid == false)
{
if (inputGPUTemperature >= 25 && inputGPUTemperature <= 35)
{
if (coolingTimeGPU == 0)
{
isGPUWasCoolValid = true;
isGPUCoolValid = true;
}
else
{
isGPUCoolingValid = true;
isGPUCoolValid = true;
}
}
}
}
if ((inputCPUTemperature > 85 && inputCPUTemperature <= 95) || (inputGPUTemperature > 85 && inputGPUTemperature <= 95))
{
if (inputCPUTemperature > 85 && inputCPUTemperature <= 95)
{
fanRotationSpeedCPU = 4200;
inputCPUTemperature -= 2;
Console.ForegroundColor = ConsoleColor.DarkCyan;
if (coolingTimeCPU == 0)
{
Console.WriteLine($"\nCPU Cooling Started, The Current Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe Current CPU Fan Rotation Speed Is: ({fanRotationSpeedCPU})RPM^^");
}
else
{
Console.WriteLine($"The CPU Cooling Time Is: ({coolingTimeCPU})Minutes^^" +
$"\nThe Current Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe Current CPU Fan Rotation Speed Is: ({fanRotationSpeedCPU})RPM^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
coolingTimeCPU++;
}
if (inputGPUTemperature > 85 && inputGPUTemperature <= 95)
{
fanRotationSpeedGPU = 4200;
inputGPUTemperature -= 2;
Console.ForegroundColor = ConsoleColor.DarkGreen;
if (coolingTimeGPU == 0)
{
Console.WriteLine($"\nGPU Cooling Started, The Current Temperature Is: ({inputGPUTemperature})C Degrees^^" +
$"\nThe Current GPU Fan Rotation Speed Is: ({fanRotationSpeedGPU})RPM^^");
}
else
{
Console.WriteLine($"\nThe GPU Cooling Time Is: ({coolingTimeGPU})Minutes^^" +
$"\nThe Current Temperature Is: ({inputGPUTemperature})C Degrees^^" +
$"\nThe Current GPU Fan Rotation Speed Is: ({fanRotationSpeedGPU})RPM^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
coolingTimeGPU++;
}
}
else if ((inputCPUTemperature > 75 && inputCPUTemperature <= 85) || (inputGPUTemperature > 75 && inputGPUTemperature <= 85))
{
if (inputCPUTemperature > 75 && inputCPUTemperature <= 85)
{
fanRotationSpeedCPU = 3500;
inputCPUTemperature -= 2;
Console.ForegroundColor = ConsoleColor.DarkCyan;
if (coolingTimeCPU == 0)
{
Console.WriteLine($"\nThe CPU Cooling Started, The Current Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe Current CPU Fan Rotation Speed Is: ({fanRotationSpeedCPU})RPM^^");
}
else
{
Console.WriteLine($"\nThe CPU Cooling Time Is: ({coolingTimeCPU})Minutes^^" +
$"\nThe Current CPU Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe Current CPU Fan Rotation Is: ({fanRotationSpeedCPU})RPM^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
coolingTimeCPU++;
}
if (inputGPUTemperature > 75 && inputGPUTemperature <= 85)
{
fanRotationSpeedGPU = 3500;
inputGPUTemperature -= 2;
Console.ForegroundColor = ConsoleColor.DarkGreen;
if (coolingTimeGPU == 0)
{
Console.WriteLine($"\nThe GPU Cooling Started, The Current GPU Temperature Is: ({inputGPUTemperature})C Degrees^^" +
$"\nThe Current GPU Fan Rotation Speed Is: ({fanRotationSpeedGPU})RPM^^");
}
else
{
Console.WriteLine($"\nThe GPU Cooling Time Is: ({coolingTimeGPU})Minutes^^" +
$"\nThe Current GPU Temperature Is: ({inputGPUTemperature})C Degrees^^" +
$"\nThe Current Fan Rotation Speed Is: ({fanRotationSpeedGPU})RPM^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
coolingTimeGPU++;
}
}
else if ((inputCPUTemperature > 65 && inputCPUTemperature <= 75) || (inputGPUTemperature > 65 && inputGPUTemperature <= 75))
{
if (inputCPUTemperature > 65 && inputCPUTemperature <= 75)
{
fanRotationSpeedCPU = 2800;
inputCPUTemperature -= 2;
Console.ForegroundColor = ConsoleColor.DarkCyan;
if (coolingTimeCPU == 0)
{
Console.WriteLine($"\nThe CPU Cooling Started, The Current CPU Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe Current CPU Fan Rotation Speed Is: ({fanRotationSpeedCPU})RPM^^");
}
else
{
Console.WriteLine($"\nThe CPU Cooling Time Is: ({coolingTimeCPU})Minutes^^" +
$"\nThe Current CPU Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe Current CPU Fan Rotation Speed Is: ({fanRotationSpeedCPU})RPM^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
coolingTimeCPU++;
}
if (inputGPUTemperature > 65 && inputGPUTemperature <= 75)
{
fanRotationSpeedGPU = 2800;
inputGPUTemperature -= 2;
Console.ForegroundColor = ConsoleColor.DarkGreen;
if (coolingTimeGPU == 0)
{
Console.WriteLine($"\nThe GPU Cooling Started, The Current GPU Temperature Is: ({inputGPUTemperature})C Degrees^^" +
$"\nThe Current GPU Fan Rotation Speed Is: ({fanRotationSpeedGPU})RPM^^");
}
else
{
Console.WriteLine($"\nThe GPU Cooling Time Is: ({coolingTimeGPU})Minutes^^" +
$"\nThe Current GPU Temperature Is: ({inputGPUTemperature})C Degrees^^" +
$"\nThe Current GPU Fan Rotation Speed Is: ({fanRotationSpeedGPU})RPM^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
coolingTimeGPU++;
}
}
else if ((inputCPUTemperature > 55 && inputCPUTemperature <= 65) || (inputGPUTemperature > 55 && inputGPUTemperature <= 65))
{
if (inputCPUTemperature > 55 && inputCPUTemperature <= 65)
{
fanRotationSpeedCPU = 2100;
inputCPUTemperature -= 2;
Console.ForegroundColor = ConsoleColor.DarkCyan;
if (coolingTimeCPU == 0)
{
Console.WriteLine($"\nThe CPU Cooling Started, The Current CPU Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe Current CPU Fan Rotation Speed Is: ({fanRotationSpeedCPU})RPM^^");
}
else
{
Console.WriteLine($"\nThe CPU Cooling Time Is: ({coolingTimeCPU})Minutes^^" +
$"\nThe Current CPU Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe Current CPU Fan Rotation Speed Is: ({fanRotationSpeedCPU})RPM^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
coolingTimeCPU++;
}
if (inputGPUTemperature > 55 && inputGPUTemperature <= 65)
{
fanRotationSpeedGPU = 2100;
inputGPUTemperature -= 2;
Console.ForegroundColor = ConsoleColor.DarkGreen;
if (coolingTimeGPU == 0)
{
Console.WriteLine($"\nThe GPU Cooling Started, The Current GPU Temperature Is: ({inputGPUTemperature})C Degrees^^" +
$"\nThe Current GPU Fan Rotation Speed Is: ({fanRotationSpeedGPU})RPM^^");
}
else
{
Console.WriteLine($"\nThe GPU Cooling Time Is: ({coolingTimeGPU})Minutes^^" +
$"\nThe Current GPU Temperature Is: ({inputGPUTemperature})C Degrees^^" +
$"\nThe Current GPU Fan Rotation Speed Is: ({fanRotationSpeedGPU})RPM^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
coolingTimeGPU++;
}
}
else if ((inputCPUTemperature > 45 && inputCPUTemperature <= 55) || (inputGPUTemperature > 45 && inputGPUTemperature <= 55))
{
if (inputCPUTemperature > 45 && inputCPUTemperature <= 55)
{
fanRotationSpeedCPU = 1400;
inputCPUTemperature -= 2;
Console.ForegroundColor = ConsoleColor.DarkCyan;
if (coolingTimeCPU == 0)
{
Console.WriteLine($"\nThe CPU Cooling Started, The Current CPU Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe Current CPU Fan Rotation Speed Is: ({fanRotationSpeedCPU})RPM^^");
}
else
{
Console.WriteLine($"\nThe CPU Cooling Time Is: ({coolingTimeCPU})Minutes^^" +
$"\nThe Current CPU Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe Current CPU Fan Rotation Speed Is: ({fanRotationSpeedCPU})RPM^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
coolingTimeCPU++;
}
if (inputGPUTemperature > 45 && inputGPUTemperature <= 55)
{
fanRotationSpeedGPU = 1400;
inputGPUTemperature -= 2;
Console.ForegroundColor = ConsoleColor.DarkGreen;
if (coolingTimeGPU == 0)
{
Console.WriteLine($"\nThe GPU Cooling Started, The Current CPU Temperature Is: ()C Degrees^^" +
$"\nThe Current GPU Fan Rotation Speed Is: ({fanRotationSpeedGPU})RPM^^");
}
else
{
Console.WriteLine($"\nThe CPU Cooling Time Is: ({coolingTimeGPU})Minutes" +
$"\nThe Current GPU Temperature Is: ({inputGPUTemperature})C Degrees^^" +
$"\nThe Current GPU Fan Rotation Speed Is: ({fanRotationSpeedGPU})RPM");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
coolingTimeGPU++;
}
}
else if ((inputCPUTemperature > 35 && inputCPUTemperature <= 45) || (inputGPUTemperature > 35 && inputGPUTemperature <= 45))
{
if (inputCPUTemperature > 35 && inputCPUTemperature <= 45)
{
fanRotationSpeedCPU = 700;
inputCPUTemperature -= 2;
Console.ForegroundColor = ConsoleColor.DarkCyan;
if (coolingTimeCPU == 0)
{
Console.WriteLine($"\nThe CPU Cooling Started, The Current CPU Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe Current CPU Fan Rotation Speed Is: ({fanRotationSpeedCPU})RPM^^");
}
else
{
Console.WriteLine($"\nThe CPU Cooling Time Is: ({coolingTimeCPU})Minutes^^" +
$"\nThe Current CPU Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe Current CPU Fan Rotation Speed Is: ({fanRotationSpeedCPU})RPM^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
coolingTimeCPU++;
}
if (inputGPUTemperature > 35 && inputGPUTemperature <= 45)
{
fanRotationSpeedGPU = 700;
inputGPUTemperature -= 2;
Console.ForegroundColor = ConsoleColor.DarkGreen;
if (coolingTimeGPU == 0)
{
Console.WriteLine($"\nThe GPU Cooling Started, The Current GPU Temperature Is: ({inputGPUTemperature})C Degrees^^" +
$"\nThe Current GPU Fan Rotation Speed Is: ({fanRotationSpeedGPU})RPM^^");
}
else
{
Console.WriteLine($"\nThe GPU Cooling Time Is: ({coolingTimeGPU})Minutes^^" +
$"\nThe Current GPU Temperature Is: ({inputGPUTemperature})C Degrees^^" +
$"\nThe Current GPU Fan Rotation Speed Is: ({fanRotationSpeedGPU})RPM^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
coolingTimeGPU++;
}
}
}
while (!isCPUCoolValid || !isGPUCoolValid);
Console.ForegroundColor = ConsoleColor.Green;
if (isCPUWasCoolValid == true)
{
Console.WriteLine("\nCPU Temperature Is Suitable And Does Not Need Cooling^^");
}
else if (isCPUCoolingValid == true)
{
Console.WriteLine("\nThe CPU Has Successfully Cooled Down And CPU Fan Has Turned Off^^" +
$"\nThe Current CPU Temperature Is: ({inputCPUTemperature})C Degrees^^" +
$"\nThe CPU Cooled Down After ({coolingTimeCPU})Minutes^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Green;
if (isGPUWasCoolValid == true)
{
Console.WriteLine("\nGPU Temperature Is Suitable And Does Not Need Cooling^^");
}
else if (isGPUCoolingValid == true)
{
Console.WriteLine("\nThe GPU Has Successfully Cooled Down And GPU Fan Has Turned Off^^" +
$"\nThe Current GPU Tepmerature Is: ({inputGPUTemperature})C Degrees^^" +
$"\nThe GPU Cooled Down After ({coolingTimeGPU})Minutes^^");
}
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
isGPUTemperatureValid = true;
}
else
{
errorsCount++;
remaining = maxErrors - errorsCount;
if (remaining > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"\nInvalid Input, Your Errors Count Number Is: ({errorsCount})!!" +
"\nThe Temperature Of The GPU Cannot Be Lower Than (25)C Degrees In Normal Mode" +
"Or It Cannot Be Higher Than (95)C Degrees Due To The Cooling System");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"You Have ({remaining}) More Chance^^");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("\nYou Have Run Out Of All Allowed Errors!!!");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
}
}
}
catch (FormatException)
{
errorsCount++;
remaining = maxErrors - errorsCount;
if (remaining > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"\nInvalid Input, Please Enter Just Number, Your Errors Count Number Is: ({errorsCount})!!");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"You Have ({remaining}) More Chance^^");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("\nYou Have Run Out Of All Allowed Errors!!!");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
}
}
catch (Exception ex)
{
errorsCount++;
remaining = maxErrors - errorsCount;
if (remaining > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"\nUnexcpected Error Occured ({ex.Message}), Please Enter Number Correctly" +
$"\nYour Errors Count Number Is: ({errorsCount})!!");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"You Have ({remaining}) More Chance^^");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("\nYou Have Run Out Of All Allowed Errors!!!");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
}
}
}
while (!isGPUTemperatureValid && errorsCount < maxErrors);
isCPUTemperatureValid = true;
}
else
{
errorsCount++;
remaining = maxErrors - errorsCount;
if (remaining > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"\nInvalid Input, Your Errors Count Number Is: ({errorsCount})!!" +
"\nThe Temperature Of The CPU Cannot Be Lower Than (25)C Degrees In Normal Mode" +
"\nOr It Cannot Be Higher Than (95)C Degrees Due To The Cooling Syetem");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"You Have ({remaining}) More Chance^^");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("\nYou Have Run Out Of All Allowed Errors!!!");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
}
}
}
catch (FormatException)
{
errorsCount++;
remaining = maxErrors - errorsCount;
if (remaining > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"\nInvalid Input, Please Enter Just Number, Your Errors Count Number Is: ({errorsCount})!!");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"You Have ({remaining}) More Chance^^");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("\nYou Have Run Out Of All Allowed Errors!!!");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
}
}
catch (Exception ex)
{
errorsCount++;
remaining = maxErrors - errorsCount;
if (remaining > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"\nUnexcpected Error Occured ({ex.Message}), Please Enter Number Correctly" +
$"\nYour Errors Count Number Is: ({errorsCount})!!");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"You Have ({remaining}) More Chance^^");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("\nYou Have Run Out Of All Allowed Errors!!!");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("\n*******************************************************************");
Console.ResetColor();
}
}
}
Console.ReadKey();