Whats wrong with my code?
Aug 31, 2014 at 1:58pm UTC
Hello Everyone. This has been bothering me for a while now and for most of my programs, the line ' if (gender == male)' always has an error! Could someone tell me what the hell i'm doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name = "" ;
string gender = "" ;
int age;
int height;
int weight;
cout << "Please Enter Your Full Name:\n" << endl;
getline (cin, name);
cout << "---\n" << endl;
cout << "Please Enter Your Gender (Male/Female):\n" << endl;
getline (cin, gender);
if (gender == male)
{
cout << "You selected Male.\n" << endl;
}
else if (gender == Female)
{
cout << "You Selected Female" << endl;
}
cout << "---\n" << endl;
cout << "Please Enter Your Age:\n" << endl;
cin >> age;
if (age > 18)
{
cout << "You are an Adult.\n" << endl;
}
else if (age < 18)
{
cout << "You are not an adult.\n" << endl;
}
cout << "---\n" << endl;
cout << "Please Enter Your Height(cm):\n" << endl;
cin >> height;
cout << "---\n" << endl;
cout << "Please Enter your Total Weight(kg):\n" << endl;
cin >> weight;
cout << "----------\n" << endl;
cout << "Name: " << name << "\n" << endl;
cout << "Age: " << age << "\n" << endl;
cout << "Gender: " << gender << "\n" << endl;
cout << "Height: " << height << "cm \n" << endl;
cout << "Weight: " << weight << "kg \n" << endl;
cout << "Database Saved.\n" << endl;
cout << "----------\n" << endl;
system("PAUSE" );
return 0;
}
Aug 31, 2014 at 2:06pm UTC
@Wulfinite
You have to put the words Male and Female that you are checking the variable, Gender, against, into quotation marks.
Aug 31, 2014 at 5:01pm UTC
Aug 31, 2014 at 6:01pm UTC
instead of typing input you can give the user choice like
1 2 3 4 5 6
cout<<"your gender \n1.male\n2.female " ;
cin>>gender;
if (gender==1)
cout<<"you selected male" ;
else if (gender==2)
cout<<"you selected female" ;
it would also be great if you would use
float
in height and weight
Sep 3, 2014 at 12:19pm UTC
Thanks guys :) I appreciate your suggestions and help. Solved.
Sep 3, 2014 at 12:28pm UTC
@programmer
read the OP's code
the input has to be read in string.
Topic archived. No new replies allowed.