-Write in C# Pick at least 5 countries, research their populations and capitals.
ID: 3801221 • Letter: #
Question
-Write in C# Pick at least 5 countries, research their populations and capitals. Request the name of the country from the user, then using a switch display the population and the capital of the entered country.
-Write a loop to add all the consecutive integers between 5 and 45 except the 12, 25, and 40. Display the final sum.
-A store sells two items (Item1 and Item2). Item1 is priced at $3.95 and Item2 is priced at $2.50. Request from the user the quantity of Item1 purchased and the quantity of Item2 purchased. Calculate item1subtotal, item2Subbotal, subtotals, tax and total. Display all. (tax is 9.8% or 0.098)
-Write a program that allows the user 13 tries to answer the question: “Which U.S. President was born on July 4?” After 5 incorrect guesses the program should give the hint: “ He once said, ‘if you don’t say anything, you won’t be called upon to repeat it.’ “. After 10 incorrect guesses, the program should give the hint “ His nickname was ‘Silent Cal.’”. Note: Calvin Coolidge was born on July 4, 1872.
-Request two values from user N and M, where N is the number of stars per line and M is the number of rows (lines) Display as many rows and columns of stars
-Create an array of doubles and initialize it with the following values: -3.5, 2.3, 5.9, -6.9, -12.1, 15.6, 4.7, -3.8, -17.3, -11.4, 12.6, 19.9
-Write a statemenent to change the fifth element to the new value: 16.9
-Write a statement to decrease the last element by 3.7
Explanation / Answer
C# CODE FOR PROGRAM 1
using System;
//main class begins
class Program3
{
//main method begins
static void Main()
{
while(true)
{
//display of menu
Console.WriteLine(" 1. South Korea");
Console.WriteLine("2. United Kingdom");
Console.WriteLine("3. Thailand");
Console.WriteLine("4. PhilippinesDivide");
Console.WriteLine("5. Spain");
Console.WriteLine("6. Exit");
//getting choice from the user
Console.WriteLine(" Enter your choice of country: ");
String country=Console.ReadLine();
int choice=Convert.ToInt32(country);
//depends upon the choice of the user, any one of the case will be selected and executed
switch(choice)
{
case 1: Console.WriteLine(" Capital of South Korea is Seoul");
Console.WriteLine(" Population of South Korea is 50,503,933 ");
break;
case 2: Console.WriteLine(" Capital of United Kingdom is London");
Console.WriteLine(" Population of South Korea is 65,111,143");
break;
case 3: Console.WriteLine(" Capital of Thailand is Bangkok");
Console.WriteLine(" Population of Thailand is 68,146,609");
break;
case 4: Console.WriteLine(" Capital of Philippines is Manila");
Console.WriteLine(" Population of Philippines is 102,250,133");
break;
case 5: Console.WriteLine(" Capital of Spain is Madrid");
Console.WriteLine(" Population of Spain is 46,064,604");
break;
case 6:Environment.Exit(0);
break;
default:
Console.WriteLine(" enter a valid choice");
break;
}
}
}
}
C# CODE FOR PROGRAM 2
using System;
//main class begins
class Program5
{
//main method begins
static void Main()
{
int sum=0;
for(int i=5;i<=45;i++)
{
if (i==12 || i==25 || i==40)
continue;
else
{
sum+=i;
}
}
Console.WriteLine("The sum of numbers from 5 to 45 except 12,25 and 40 is "+sum);
}
}
C# FOR PROGRAM 3
using System;
//main class begins
class Program5
{
//main method begins
static void Main()
{
Console.WriteLine("Enter the number of quantity for Item1 purchased");
String s1=Console.ReadLine();
Console.WriteLine("Enter the number of quantity for Item2 purchased");
String s2=Console.ReadLine();
int item1=Convert.ToInt32(s1);
int item2=Convert.ToInt32(s2);
double item1subtotal=item1 * 3.95;
double item2subtotal=item2 * 2.50;
double subtotal=item1subtotal + item2subtotal;
double tax=0.098 * subtotal;
double total=subtotal + tax;
Console.WriteLine(" Subtotal for item1 " + item1subtotal);
Console.WriteLine(" Subtotal for item2 " + item2subtotal);
Console.WriteLine(" Subtotal " + subtotal);
Console.WriteLine(" Tax " + tax);
Console.WriteLine(" Total " + total);
}
}
C# CODE FOR PROGRAM 4
using System;
//main class begins
class Program7
{
//main method begins
static void Main()
{
int attempt=0;
Console.WriteLine("Which US president was born on July 4?");
while(attempt<13)
{
attempt++;
String answer=Console.ReadLine();
answer=answer.ToLower();
if(answer=="calvin coolidge")
{
Console.WriteLine("Congrats! --- You have answer is correct");
break;
}
else
{
Console.WriteLine("No You are wrong!");
}
if(attempt>5 && attempt <=10)
{
Console.WriteLine("Hint: He once said, ‘if you don’t say anything, you won’t be called upon to repeat it.’");
}
else
{
if(attempt>10)
{
Console.WriteLine("Hint: His nickname was ‘Silent Cal.’");
}
}
}
}
}
C# CODE FOR PROGRAM 5
using System;
//main class begins
class Program8
{
//main method begins
static void Main()
{
Console.WriteLine("Enter the value for M");
String s1=Console.ReadLine();
Console.WriteLine("Enter the value for N");
String s2=Console.ReadLine();
int m=Convert.ToInt32(s1);
int n=Convert.ToInt32(s2);
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
}
C# CODE FOR PROGRAM 6
using System;
//main class begins
class Program8
{
//main method begins
static void Main()
{
double[] arr={-3.5,2.3,5.9,-6.9,-12.1,15.6,4.7,-3.8,-17.3,-11.4,12.6,19.9};
Console.WriteLine("Before changing");
for(int i=0;i<10;i++)
Console.WriteLine(arr[i]);
arr[4]=16.9;
arr[9]=arr[9]-3.7;
Console.WriteLine("After changing");
for(int j=0;j<10;j++)
Console.WriteLine(arr[j]);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.