need help! plz

i'm pretty new and can use some help here is the code and error

[code]
//This is for testing code to see how it works
#include <stdafx.h>
#include <iostream>

using namespace std;

int main ()
{
char name2[40];
double age2;
char r;
char name[20];
double age;
int yes;
int no;

cout <<"what is him/her's name?" << endl;
cin>>name;
cout <<"what is their age?" << endl;
cin>>age;
cout <<"Do you want to enter more data?" << endl;
cin>>r;
if (r == "yes")
goto label1;
if (r == "no")
goto done;
cin.ignore();
cin.get();


label1:
{
cout <<"what is him/her's name?" << endl;
cin>>name2;
cout <<"what is their age?" << endl;
cin>>age2;
goto done;

}

done:
{
cout <<"hi" << endl;
system("pause>nul");

}
}



ERRORS:
code.cpp(23) : error C2446: '==' : no conversion from 'const char *' to 'int'
-----------------------------------------------------------------------------
code.cpp(23) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [4]'
------------------------------------------------------------------------------
code.cpp(25) : error C2446: '==' : no conversion from 'const char *' to 'int'
------------------------------------------------------------------------------
error C2040: '==' : 'int' differs in levels of indirection from 'const char [3]
if you are doing names, try string, and not char since you are not inputting a single character, or are you? for their name
closed account (j3Rz8vqX)
In both your if statements, you're comparing a c_string against a character value.

Which is invalid.

A possible solution:
Change "yes" to 'y' and "no" to 'n', and use y/n for your more data entry determination.
Your error kind of mentions then comparing a single character to a string of characters and the line number.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
char r;
if (r == "yes") //how is 1 character equal to 3 characters?
if (r == "no") //same as the one above


double age; //why is age a double? Someone is 10.234 years old? Seems weird
double age2; //Same as above


//All of these should be avoided
goto label1;
goto done;
label1:
done:
goto done;



thx for the reply i will try string and see what happens :)
It worked by using string! Thanks so much!! i know i seem like total noob and i am so sorry
yeah haha good job, bud
Topic archived. No new replies allowed.