Your Assignment: This code is written in C#. Please correct this code so that it
ID: 3887107 • Letter: Y
Question
Your Assignment: This code is written in C#. Please correct this code so that it compiles and runs. This program contains 4 errors! Don't just correct the code but ALSO EXPLAIN WHAT YOU FIXED AND WHY!!
namespace DailyRate
{
class Program
{
static void Main(string[] args)
{
(new Program()).run();
}
void run()
{
double dailyRate = readDouble("Enter your daily rate: ");
int noOfDays = readInt("Enter the number of days: ");
writeFee(calculateFee(dailyRate, noOfDays));
}
private void writeFee(double p, int n)
{
Console.WriteLine("The consultant's fee is: {0}", p * 1.1);
}
private double calculateFee(double dailyRate, int noOfDays);
{
return dailyRate * noOfDays;
}
private double readInt(string p)
{
Console.Write(p);
string line = Console.ReadLine();
return int.Parse(line);
}
private double readDouble(int p)
{
Console.Write(p);
string line = Console.ReadLine();
return double.Parse(line);
}
}
}
Explanation / Answer
//To use Console you should use the statement using System;
using System;
namespace DailyRate {
class Program {
static void Main(string[] args) {
(new Program()).run();
}
void run() {
double dailyRate = readDouble("Enter your daily rate: ");
int noOfDays = readInt("Enter the number of days: ");
writeFee(calculateFee(dailyRate, noOfDays));
}
//writeFee should have only one argument, int is not necessary.
private void writeFee(double p) {
Console.WriteLine("The consultant's fee is: {0}", p * 1.1);
}
// private double calculateFee(double dailyRate, int noOfDays); remove the semicolon at the end
private double calculateFee(double dailyRate, int noOfDays) {
return dailyRate * noOfDays;
}
// return type of readInt should be int not double
private int readInt(string p) {
Console.Write(p);
string line = Console.ReadLine();
return int.Parse(line);
}
//readDouble argument type should be string not int
private double readDouble(string p) {
Console.Write(p);
string line = Console.ReadLine();
return double.Parse(line);
}
}
}
/*
sample output
Enter your daily rate: 3
Enter the number of days: 10
The consultant's fee is: 33
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.