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)

Member Avatar for iamthwee

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

char sex;


cin>>sex;

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

hmm, I´t did almoast solve it... I´ll try to figure it out..

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.