class Timerange{
    public:
        Start_time start;
        End_time end;
        Timerange(string initstring){
            //initstring xx:xx X, x:x
            //X->weekday
            string current="";
            unsigned short mode=0;
            string timeA;
            string weekday;
            string timeB;
            for(unsigned short i = 0; i<initstring.length(); i++) {
                char c = initstring[i];
                if (c==' '){
                    if (mode==0)
                        timeA = current;
                    else if (mode==1)
                        weekday = current;
                    else if (mode==2)
                        timeB = current;
                    mode++;
                    current ="";

                };
                else{ //here
                    current+=c;
                };
            };
        };
};

it gives me error: 'else' without previous 'if''
but there is an if! What's going on?

Number one. Why all the semi-colons?

Here. Can you spot the error now?

class Timerange
{
public:

    Timerange(string initstring)
    {
        string current = "";
        unsigned short mode = 0;
        string timeA;
        string weekday;
        string timeB;
        for(unsigned short i = 0; i<initstring.length(); i++)
        {
            char c = initstring[i];
            if (c == ' ')
            {

            };//hint its here
            else
            { 

            }
        }
    }
};

Edited 2 Years Ago by gerard4143

This article has been dead for over six months. Start a new discussion instead.