0

I am new to C#. I was consulting a book by Kanetkar and solving a basic exercise with Monodevelop on Ubuntu. I chose Empty C# file from new button on toolbar. Here is the program I typed.

using System;
namespace RameshSalaryQuest {   
    class RameshSalary {        
        static void Main (String[] args) {          
            double basic, dearness, rent, gross;            
            Console.WriteLine("Enter Ramesh's Basic Salary:");
            basic = Convert.ToDouble(Console.ReadLine());           
            dearness = basic * 0.4;
            rent = basic * 0.2;         
            gross = basic + rent + dearness;            
            Console.WriteLine("Ramesh's Gross Salary is:\t"+gross);
        }
    }
}

To Build --> F7 : Build Successful

To Run --> Ctrl + F5 : This gives the following output.

Enter Ramesh's Basic Salary:
Ramesh's Gross Salary is:   0

I am not even asked to input data. Where this went wrong?

GunJack
  • 1,928
  • 2
  • 22
  • 35
  • Not `Console.WriteLine(...)`, you want `Console.ReadLine(...)` – Jeff B Dec 10 '13 at 00:27
  • Thats what I am using `Convert.ToDouble(Console.ReadLine())` – GunJack Dec 10 '13 at 00:43
  • @PaoloMoretti That solution is not working for my single file only non-project program. – GunJack Dec 10 '13 at 00:50
  • 1
    I put this into a console app on my machine and the code works fine. Running from .NET Fiddle (which I am assuming is Mono) does the same thing you describe. http://dotnetfiddle.net/RyQsTx Have you seen this answer? http://stackoverflow.com/a/740738/426422 or this one? http://stackoverflow.com/a/6809873/426422 – Mike Cheel Dec 10 '13 at 00:58
  • http://stackoverflow.com/a/740738/426422 that answer is fine but the problem is that it applies to projects/solutions not individual standalone file-programs – GunJack Dec 10 '13 at 01:01
  • @MikeCheel I checked with .NET Fiddle. Same result. – GunJack Dec 10 '13 at 01:02
  • I don't have MonoDevelop but the code runs fine on my regular windows machine so it isn't the code. – Mike Cheel Dec 10 '13 at 01:09

1 Answers1

0

I fixed this by having the program in a project instead of standalone file. This gives us the option to 'run in external console' from 'Project Option -> Run -> Run in external console' as indicated here and here.

Community
  • 1
  • 1
GunJack
  • 1,928
  • 2
  • 22
  • 35