I´m trying to put in a variable called "sex" in this program but it does´nt work, i wonder if anyone can help me with that?

#include <iostream>

using namespace std;

int main()      //viktigaste delen av programmet
{
int age;        //En variabel som heter age;
int sex;


cout<<"please input your age:";   //"cout" är det samma som "print och "echo" 
                                  //"<<" är en inputfunktion
cout<<"please input your sex (M/F):";
cin>> age;    //"cin>>"  lägger in åldern i "age;"
cin>> sex;
cin.ignore();  //
if (age < 100)  {        //om "age" är mindre än 100 
        cout<<"you are pretty young!\n";
        }
else if (age ==100 && sex == m)
     {
     cout<<"you are pretty old!\n";
     }
 else if (age ==100 && sex == f)
     {
     cout<<"you are pretty old, and u r a female!\n";
     }
 else
 {
     cout<<"You are relly old!\n";
     }
     cin.get();
}

here is the error messages:
In function `int main()':
`m' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
`f' undeclared (first use this function)

You have to declare sex as a either a char or a string.

char sex;


cin>>sex;

if (sex=='m')
{
  //do some stuff
}

Life will be simpler if you always take user input as a std::string using getline (and later convert it to a number if need be).

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