-Using C# Write a program that reads the quantity of an item and the unit price
ID: 3865011 • Letter: #
Question
-Using C# Write a program that reads the quantity of an item and the unit price of the item from the user, then calculate and display the subtotal, tax (at 9%), and total.
-Request 3 integer values, display the middle value.
-Write code to get three values from user, then determine and display the smallest one.
-The freezing point of Ethyl Alcohol is -173 and the boiling point is 172, write code to request the ethyl alcohol temperature (Fahrenheit) from user then display whether the temperature is at or below freezing, at or above boiling, or somewhere in-between.
-Request an integer from user, find out if the integer is divisible by 3 or by 7.
-Write code to generate 2 random values. The first one should be between -10 and 10 ( both inclusive), the second one should be between 50 and 100 (also both inclusive). Display these values.
-Write a while loop to display your name 15 times, each time on a separate line.
-Write code to: request an initial integer value from user, then use a while loop to display the next 20 consecutive integer values.
To convert from Fahrenheit (F) to Celsius (C), use the formula C = 5 * (F – 32)/9
Use a while loop to calculate and display the Celsius values for each Fahrenheit (F) value ranging from 0 to 50 (incrementing by 1).
Explanation / Answer
using System.IO;
using System;
class Program
{
static void Main()
{
/*
* Question -1
*/
int quantityOfItems;
double pricePerItem;
Console.Write("Enter the quantity of item : ");
int.TryParse(Console.ReadLine(), out quantityOfItems);
Console.Write("Enter the price per item : ");
double.TryParse(Console.ReadLine(), out pricePerItem);
double subTotal = (quantityOfItems * pricePerItem);
subTotal -= (subTotal * 0.09);
Console.WriteLine("SubTotal is "+subTotal+" ");
/*
* Question-2&3
*/
int[] a = new int[3];
for (int i=0; i<3; i++) {
Console.Write("Enter value-" + (i+1) + " : ");
int.TryParse(Console.ReadLine(), out a[i]);
}
int maxIndex = 0;
int minimumValue = a[0];
for (int i=1; i<3; i++) {
if (a[i] > a[maxIndex]) {
maxIndex = i;
}
if (a[i] < minimumValue) {
minimumValue = a[i];
}
}
a[maxIndex] = int.MinValue;
maxIndex = 0;
for (int i=1; i<3; i++) {
if (a[i] > a[maxIndex]) {
maxIndex = i;
}
}
Console.WriteLine("Middle Number is "+ a[maxIndex]);
Console.WriteLine("Minimum Number is "+ minimumValue+" ");
/*
* Question Number 4
*/
double freezingPoint = -173;
double boilingPoint = 172;
double userTemp;
Console.Write("Enter temperature of Ethyl Alcholol (F) : ");
double.TryParse(Console.ReadLine(), out userTemp);
if (userTemp < freezingPoint) {
Console.WriteLine("Given Temperature is below freezing point ");
}
else if (userTemp > boilingPoint) {
Console.WriteLine("Given Temperature is above boiling point ");
}
else {
Console.WriteLine("Given Temperature is within range ");
}
/*
* Question Number 5
*/
int number;
Console.Write("Enter an integer value : ");
int.TryParse(Console.ReadLine(), out number);
if (number%7 == 0) {
Console.WriteLine("Number is divisible by 7 ");
}
else if (number%3 == 0) {
Console.WriteLine("Number is divisible by 3 ");
}
else {
Console.WriteLine("Number is niether divisible by 3 nor by 7 ");
}
/*
* Question Number 5
*/
Random rand = new Random();
int firstRandNum = rand.Next(-10, 11);
int secondRandNum = rand.Next(50, 101);
Console.WriteLine("The two random numbers are : "+ firstRandNum+", "+secondRandNum+" ");
/*
* Question Number 6
*/
String myName = "Zubair";
int counter = 1;
while (counter<=15) {
Console.WriteLine(myName);
counter++;
}
Console.WriteLine(" ");
/*
* Question Number 7
*/
int userInputNum;
Console.Write("Enter a number : ");
int.TryParse(Console.ReadLine(), out userInputNum);
int endValue = userInputNum + 20;
while (userInputNum <= endValue) {
Console.Write(userInputNum +" ");
userInputNum = userInputNum + 1;
}
Console.WriteLine(" ");
/*
* Question Number 8
*/
for (double F=0; F<=50; F++) {
double C = 5.0*(F-32.0)/9.0;
Console.WriteLine("Faranhiet = "+F+", Celsius = "+C);
}
Console.WriteLine(" ");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.