Muhammad Hussain
Muhammad Hussain

Reputation: 21

I keep getting the same error, " CS1525: Unexpected symbol `string' ". I just can't find where I made an error

I just want to start by saying I'm relatively new to programming, so I don't know much about these errors, anyway, this is my code where I keep getting the "unexpected symbol string" error:

using System;

class MainClass {
  public static void Main (string[] args) 
  {

    Console.WriteLine ("Welcome to the Mushroom Kingdom bank. The Only bank in The World That Converts Real Money to Gold Coins!");

    int pass1 = 1900;
    int pass2 = 85;
    Console.WriteLine("Please enter the password, so we can confirm you are a real person.");
    Console.WriteLine($"The password is {pass1} plus {pass2}");
    Console.WriteLine("Please enter the password");
    string userPass = 
    Console.ReadLine();
    string correctPass = "1985";
    bool answer = userPass == correctPass;
    Console.WriteLine(answer);

    if (userPass == correctPass) 
    {
      Console.WriteLine("Please Choose An Option");
    } 
    else 
    {
      Console.WriteLine("Incorrect, Restart Progtam");

    }
      Console.WriteLine("Your starting balance is 200 gold coins. This converts to 288 US Dollars");
      Console.WriteLine("-> Deposit <-");
      Console.WriteLine("-> Withdraw <-");


      double CoinValue = 1.44;
      double coinBalance = 200

      string userChoice = Console.ReadLine();
      userChoice.ToUpper();

    if (userChoice == "DEPOSIT")
    {
    Console.WriteLine("Enter an amount to deposit");
    string depamount = Console.ReadLine();
    double dubamount = Convert.ToDouble(depamount);
    double nxtBalance = (dubamount / CoinValue) + coinBalance;
    Console.WriteLine($"{depamount} has been converted to {CoinValue} gold coins.");

    }
    else if (userChoice== "WITHDRAW")
    {
    Console.WriteLine("Enter an amount to withdraw");
    string widamount = Console.ReadLine();
    double dubwidamount = Convert.ToDouble(widamount);
    double widcoin = dubwidamount / CoinValue;
    double newBalance = coinBalance - widcoin;
    Console.WriteLine($"You have withdrawed {widcoin} gold coins from your account. Your remaining balance is {coinBalance} gold coins");



    }



  }
}

Anyways, I hope somebody out there can help me with this problem.

Upvotes: 0

Views: 7505

Answers (2)

Oleg Skripnyak
Oleg Skripnyak

Reputation: 311

There is just error in the following line, you've missed semicolon

double coinBalance = 200;

Btw. There is an error in the code, its could be

string userChoice = Console.ReadLine().ToUpper();

because string.ToUpper() function returns string, but not working over instace of a string.

But still not, say in Turkish location, "deposit" in upper case will become "DEPOSİT", where "i" becomes "İ", so its not correct (you should never know about, and 99% of here developers, only experience) Correct comparison is:

if (string.Compare(userChoice, "deposit", StringComparison.InvariantCultureIgnoreCase) == 0)

Upvotes: 2

nulltron
nulltron

Reputation: 646

Just as @Oleg pointed out you're missing line terminator. The string error you're receiving is from this line:

double coinBalance = 200 // this line isn't terminated

string userChoice = Console.ReadLine(); // compiler doesn't understand where the string type is coming from

FIX:

double coinBalance = 200; 

string userChoice = Console.ReadLine();

Upvotes: 0

Related Questions