Reputation: 135
I am having problem with the if and for loop. The first closing bracket(}) is closing the first if statement. What I wanted to do is to close the bracket that it is aligned with.
startnum = int.Parse(startnumbers);
endnum = int.Parse(endnumbers);
string route = "1. ";
if (startletters == endletters && startnum > endnum)
{
for (int count = 0; startnum < endnum; startnum++)
{
if (startname != endname)
{
count++;
route += ("Board the {0} line, go {1} stops toward {2}",startletters,count, endname );
}
}
}
Upvotes: 0
Views: 87
Reputation: 1627
The following mistakes that you are going to make:
How to solve it ?
The following ways to sovle this problem are:
Your Code [Corrected] :
startnum = int.Parse(startnumbers);
endnum = int.Parse(endnumbers);
string route = "1.";
if (startletters == endletters && startnum > endnum)
{
for (int count = 0; startnum < endnum; startnum++)
{
if (startname != endname)
{
count++;
string tempRoute = string.Format("Board the {0} line, go {1} stops toward {2}",startletters,count, endname);
route = route + " " + tempRoute;
}
}
}
Upvotes: 1
Reputation: 4947
You have a syntax error is in this line:
route += ("Board the {0} line, go {1} stops toward {2}",startletters,count, endname );
You have the parameters for string.Format
but you're not actually calling it. You want this instead:
route += string.Format("Board the {0} line, go {1} stops toward {2}", startletters, count, endnum);
Because of the syntax error, the compiler isn't able to match the braces as you expect.
Upvotes: 3