0% found this document useful (0 votes)
41 views

CHAPTER 2: Variables and Data Types

The document discusses variables and data types in C# by defining several variables such as minimum temperature, maximum temperature, average temperature, population of a town and state, literacy percentage, and whether a city is a metropolis. It then prompts the user to input values for each variable and displays the values back to the user. The variables are of different data types including double, int, bool, float, and string.

Uploaded by

Ilma Fareez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

CHAPTER 2: Variables and Data Types

The document discusses variables and data types in C# by defining several variables such as minimum temperature, maximum temperature, average temperature, population of a town and state, literacy percentage, and whether a city is a metropolis. It then prompts the user to input values for each variable and displays the values back to the user. The variables are of different data types including double, int, bool, float, and string.

Uploaded by

Ilma Fareez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CHAPTER 2 : Variables and Data Types

using System;
namespace atlantiscientificsystems
{
class Program
{
static void Main(string[] args)
{
double minTemp;
double maxTemp;
double avgTemp;
int populationtown;
int populationstate;
bool metropolis;
float literacypercent;
string avgqualification;

Console.WriteLine("Enter the minimum temperature");


minTemp = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The minimum temperature is :" + minTemp+ " C");
Console.ReadKey();
Console.WriteLine("Press enter to continue");
Console.WriteLine();

Console.WriteLine("Enter the maximum temperature");


maxTemp = Convert.ToDouble(Console.ReadLine());
if (maxTemp < minTemp)
{
Console.WriteLine("ERROR - Please enter valid maximum temperature");
}
else
{
Console.WriteLine(" The maximum temperature is :" + maxTemp + " C");
}
Console.ReadKey();
Console.WriteLine("Press enter to continue");
Console.WriteLine();

Console.WriteLine("Enter the average temperature");


avgTemp = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The average temperature is :" + avgTemp +"C");
Console.ReadKey();
Console.WriteLine("Press enter to continue");
Console.WriteLine();

Console.WriteLine("Enter the population of the town");


populationtown = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The population of the town is :" + populationtown);
Console.ReadKey();
Console.WriteLine("Press enter to continue");
Console.WriteLine();

Console.WriteLine("Enter the population of the state");


populationstate = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The population of the state is :" + populationstate);
Console.ReadKey();
Console.WriteLine("Press enter to continue");
Console.WriteLine();

Console.WriteLine("Is the city a metropolis? :");


metropolis = Convert.ToBoolean(Console.ReadLine());
if (metropolis == true)
{
Console.WriteLine("The city is a metropolis");
}
else if (metropolis == false)
{
Console.WriteLine("The city is not a metropolis");
}
else
{
Console.WriteLine("Invalid");
}
Console.ReadKey();
Console.WriteLine("Press enter to continue");
Console.WriteLine();

Console.WriteLine("Enter the average literacy percentage");


literacypercent = float.Parse(Console.ReadLine());
Console.WriteLine("The average literacy percentage is :" + literacypercent+
"%");
Console.ReadKey();
Console.WriteLine("Press enter to continue");
Console.WriteLine();

Console.WriteLine("Enter the average qualification - Graduate /


PostGraduate");
avgqualification = Console.ReadLine();
Console.WriteLine("The average qualification is :" + avgqualification);
Console.WriteLine("Press enter to continue");
Console.WriteLine();
Console.ReadKey();
} } }
OUTPUT:
using System;
namespace garciainfosystems
{
class Program
{
static void Main(string[] args)
{
string Studentname, Address, Fathersname, Mothername, FathersOccupation,
MajorSubject, StudentGrade, Division;
int Studentage, Dateofbirth;
char c;
char G;

Console.WriteLine("Enter student name:");


Studentname = Console.ReadLine();
Console.WriteLine("Press enter to proceed");
Console.WriteLine();
Console.ReadKey();

Console.WriteLine("Are you a male or female? ( PLEASE ENTER [ M/F ] )");


G = Convert.ToChar(Console.ReadLine());
if (G == 'M' || G == 'm')
{
Console.WriteLine("GENDER = MALE");
}
else if (G == 'F' || G == 'f')
{
Console.WriteLine("GENDER = FEMALE");
}
else
{
Console.WriteLine("INVALID");
}
Console.WriteLine("Press enter to proceed");
Console.WriteLine();
Console.ReadKey();

Console.WriteLine("Enter Address:");
Address = Console.ReadLine();
Console.WriteLine("Press enter to proceed");
Console.WriteLine();
Console.ReadKey();

Console.WriteLine("Enter Father's name:");


Fathersname = Console.ReadLine();
Console.WriteLine("Press enter to proceed");
Console.WriteLine();
Console.ReadKey();

Console.WriteLine("Enter Mother's name:");


Mothername = Console.ReadLine();
Console.WriteLine("Press enter to proceed");
Console.WriteLine();
Console.ReadKey();

Console.WriteLine("Enter Fathers Occupation:");


FathersOccupation = Console.ReadLine();
Console.WriteLine("Press enter to proceed");
Console.WriteLine();
Console.ReadKey();

Console.WriteLine("Are you a citizen or not [ Y/N ]");


c = Convert.ToChar(Console.ReadLine());
if (c == 'Y' || c == 'y')
{
Console.WriteLine(Studentname + " is a citizen");
}
else
{
Console.WriteLine(Studentname + " is not a citizen");
}
Console.WriteLine("Press enter to proceed");
Console.WriteLine();
Console.ReadKey();

Console.WriteLine("Major Subject:");
MajorSubject = (Console.ReadLine());
Console.WriteLine("Press enter to proceed");
Console.WriteLine();
Console.ReadKey();

Console.WriteLine("Enter Age:");
Studentage = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Press enter to proceed");
Console.WriteLine();
Console.ReadKey();

Console.WriteLine("Enter Date of birth {dd/MM/yyyy}");


Dateofbirth = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Press enter to proceed");
Console.WriteLine();
Console.ReadKey();

Console.WriteLine("Enter Student grade");


StudentGrade = Console.ReadLine();
Console.WriteLine("Press enter to proceed");
Console.WriteLine();
Console.ReadKey();
Console.WriteLine("ENter Student Division");
Division = Console.ReadLine();
Console.WriteLine("Press enter to proceed");
Console.WriteLine();
Console.ReadKey();

Console.WriteLine(Studentname + ("\u0020") + Fathersname + ("\u0020") + "


DETAILS:");
Console.WriteLine();
Console.WriteLine(" Student name : {0} \n Address : {1} \n Father's name :
:{2} \n Mothers name : {3} \n Father's Occupation : {4} \n Major subject
:{5} \n Student grade : {6} \n Division :{7}", Studentname, Address,
Fathersname, Mothername, FathersOccupation, MajorSubject, StudentGrade,
Division);
Console.WriteLine(" Student age: {0} \n Date of birth : {1} ", Studentage,
Dateofbirth);
Console.WriteLine(" Citizen or not (Y/y = YES) (N/n = NO)", Studentname,
c);
Console.WriteLine(" Male of Female? {0}", Studentname, G);

Console.WriteLine("Enter any key to continue");


Console.ReadKey();

}
}
}
CHAPTER 3: Statements and Operators

You might also like