Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace BC170401685
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the Numeric Characters of Your VU ID as your Assets"); ;
            int vid = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("If you want to calculate Zakat of Your amount in rupees Then Press 1" +
                "\nIf you want to calculate Zakat of your amount in Gold Then Press 2" +
                "\nIf you want to calculate Zakat of your amount in Silver Then Press 3" +
 
                int option = Convert.ToInt32(Console.ReadLine());

                switch (option)
                {
                    case 1:
                        Zakat z = new Zakat();
                        z.zakat_Calculation(vid);
                        break;
                    case 2:
                        Zakat g = new Gold();
                        g.zakat_Calculation(vid);
                        break;
                    case 3:
                        Zakat.s = new Silver();
                        s.zakat_Calculation(vid);
                        break;
                    default:
                        Console.WriteLine("Enter Correct Number");
                        break;
                }
        }
    }
}

int option = Convert.ToInt32(Console.ReadLine());

                switch (option)

here int option there is error and in 2nd line switch(option) there is error what is the problem and how can i fix it ..... Please help

What I have tried:

I checked my whole code but i cannot find any mistake what can i DO??
Posted
Updated 16-May-21 19:19pm
v2

1 solution

Look at your code, and check the lines around where the error is detected:
C#
Console.WriteLine("If you want to calculate Zakat of Your amount in rupees Then Press 1" +
    "\nIf you want to calculate Zakat of your amount in Gold Then Press 2" +
    "\nIf you want to calculate Zakat of your amount in Silver Then Press 3" +

    int option = Convert.ToInt32(Console.ReadLine());

    switch (option)
Why does this line end with a "string continuation" character?
"\nIf you want to calculate Zakat of your amount in Silver Then Press 3" +
                                                                         ^
                                                                         |

Where is the closing bracket for the call to WriteLine?
Remove the "+", finish the statement, and try again.

But ... don't use Convert methods on user input - users mistype all the time, and the Convert methods will crash if they are given "bad data" - any non-numeric character inteh case of an integer.
Instead use the TryParse methods, report problems, and ask again: Int32.TryParse Method (System) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900