If If else statment

Can anyone look at my code and explain what I could be doing wrong with this if else statement. No matter how I configure the order I continue to get an error telling my that I have an If without an else statement.I have tried doing it outside a while loop and the incrementation is also not working for me. Also is there anyway to perform an If statement with a string variable and if so how would I need to grab the user's input value and run it through a control statement. Thanks in advance for any help.

#include <iostream>
#include <string>
using namespace std;

class Date
{
public:
void setPayDate(string name)
{
userPayDate = name;
}
string getPayDate()
{
return userPayDate;
}

private:
string userPayDate;
};//end class Date
int main()
{
using namespace std;//Using Namespace library
int userIntChoice = 0;
int loop1 = 1;//declaration variable for loop
Date myDate1;//Creating object from Date class
string userInput = "No Pay";//Default value for user input

cout << "Do you get paid (1)weekly or (2)biweekly? ";
cin >> userIntChoice;


/* while(loop1 <= 2)// loop condition
loop1 = loop1++;//loop timer
{ */

if ( userIntChoice == 1 )

userInput = "weekly";
myDate1.setPayDate(userInput);
cout << "You receive a paycheck on a " << myDate1.getPayDate()<< " period!" << endl;

else if( userIntChoice == 2 )
userInput = "biweekly";
myDate1.setPayDate(userInput);
cout << "You receive a paycheck on a " << myDate1.getPayDate()<< " period!" << endl;


else cout<<"You have entered an incorrect date for pay"<< endl;

/* } */
myDate1.setPayDate(userInput);


system("pause");
Hint: You forgot to use set braces or curly braces. :)
I took your example and it worked after i used curly braces. I wont show you the code. Do it on your own.
and use code tags.
Any ideas on the second half of my question?
Read the user input into a string variable.

if (tolower(inputstring)=="weekly"){ do stuff;}
tolower only works for chars. Use #include <algorithm> and transform(str1.begin(), str1.end(), str2.begin(), tolower) where str1 is where the original string is and str2 is where the string is going. Hint: They can be the same string. Then it's if(str2 == "weekly){}
Topic archived. No new replies allowed.