-
January 3rd, 2011, 03:11 PM
#1
New Guy Help
# include <iostream>
using namespace std;
int main ()
{
char first[16];
char last[16];
char prefix[2];
char married[2];
cout << "What is your first and last name? \n";
cin >> first >> last;
cout << "Are you a man or a woman?" << endl << "Please answer with a 'm' for man or a 'w' for woman.";
cin >> prefix;
{
if (prefix = 'w') //line 18
cout << "Are you married?" << endl << "Please answer with a 'y' for yes or a 'n' for no.";
cin >> married;
if (married = 'y') //line 21
cout << "Hello Mrs. " << last << ". \n";
else if (prefix = 'n') //line 23
cout << "Hello Ms. " << last << ". \n";
}
if (prefix = 'm') //line 27
cout << "Hello Mr. " << last << ". \n";
return 0;
}
____________________________________________________________________________
Above is a project im working on to get used to C++ (just started programming yesterday) and when i try to build it i get 4 errors saying "incompatible types of assignment of 'char' to 'char[2]' " in lines 18, 21, 23 and 27. Any help would be appreciated, thanks.
-
January 3rd, 2011, 03:13 PM
#2
Re: New Guy Help
You defined prefix as a char array. My guess is that you want to check the first character. So if (prefix[0] == 'w') ...
-
January 3rd, 2011, 03:26 PM
#3
Re: New Guy Help
kk, thx, will try and let you know
-
January 3rd, 2011, 03:31 PM
#4
Re: New Guy Help
huh, it worked but now is giving me warnings on the same lines saying "suggest parentheses around assignment used as truth value" and , if its not 2 much to ask, what exactly did assigning 0 to char in the if statements do?
-
January 3rd, 2011, 03:33 PM
#5
Re: New Guy Help
nvrmd on the warnings, fixed them
-
January 3rd, 2011, 03:33 PM
#6
Re: New Guy Help
It sounds like you're still doing assignment rather than comparison as ninja suggested.
-
January 3rd, 2011, 03:43 PM
#7
Re: New Guy Help
Originally Posted by Lindley
It sounds like you're still doing assignment rather than comparison as ninja suggested.
ya, i figured that 1 out, but i still dont get what assigning 0 to char did to make this work
-
January 3rd, 2011, 03:47 PM
#8
Re: New Guy Help
Originally Posted by iiSoMeGuY 7x
but i still dont get what assigning 0 to char did to make this work
prefix[0] does not assign 0. It accesses the element of prefix at index 0.
-
January 3rd, 2011, 03:47 PM
#9
Re: New Guy Help
I don't see you assigning 0 anywhere.....please clarify your question.
-
January 3rd, 2011, 04:18 PM
#10
Re: New Guy Help
Originally Posted by laserlight
prefix[0] does not assign 0. It accesses the element of prefix at index 0.
ok, thanks
-
January 3rd, 2011, 04:26 PM
#11
Re: New Guy Help
Of course you could just define prefix and married as a single char instead of an array.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|