Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

SSJGaz

If Inside an If

This topic is 5563 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possable to have an IF inside another if? it doesnt seem to be working for me.
if( fullselection == 1)
{
cout <<"You Have Chosen To View Basic System Specs.\n" << endl ;
Sleep(1000);
cout <<"*Lynx K7SOM Mainboard" << endl;
Sleep(400);
cout <<"*Max CPU''s - One. One 500Mhz Manufactured By DMA Supplied." << endl;
Sleep(400);
cout <<"*Hard Disk Slots - Two. 24GB Supplied." << endl;
Sleep(400);
cout <<"*Modem - 1Mb DSL Supplied." << endl;
Sleep(400);
cout <<"*Cost - 16500 CR\n" << endl;
cout <<"Would You Like To Purchase This System? (Y or N)" << endl;
cin >> &buybasicsystem[0];
if( buybasicsystem == "y")
cout <<"Test" << endl;
[/soure]

when i choose to buy the system the word TEST doesnt show up, it just says Press any key to continue. 

Share this post


Link to post
Share on other sites
Advertisement
Yes.


if(fullselection == 1)
{
//...

if(buybasicsystem == "y")
{
cout << "Test" << endl;
}
else
{
cout << "Thank you for shopping with us." << endl;
}
}

You don''t need the else. It was just an example.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

Share this post


Link to post
Share on other sites
There is nothing wrong with having an if inside of an if. Your problem is using pointers. &buybasicsystem[0] is essentially the same thing as buybasicsystem, without the [0]. The name of an array is simply a pointer to the first element, so when you are doing if( buybasicsystem == "y") it is testing the address, not the value.

Change it to:

cin >> buybasicsystem[0];
if( buybasicsystem[0] == "y")

Share this post


Link to post
Share on other sites
Oh yes... When you do "y" that treats it as a string, which also includes the null terminator. Try changing it to ''y'' to treat it as a char and see what happens.

Share this post


Link to post
Share on other sites
quote:
Original post by Raloth
Oh yes... When you do "y" that treats it as a string, which also includes the null terminator. Try changing it to ''y'' to treat it as a char and see what happens.


error C2440: ''initializing'' : cannot convert from ''char [1]'' to ''char''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast

o0

Share this post


Link to post
Share on other sites
//EDIT:
Already answered

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on July 27, 2003 1:36:59 PM]

Share this post


Link to post
Share on other sites
change those last couple of lines to this ....




cin >> &buybasicsystem[0];
if( buybasicsystem[0] == 'y')
cout <<"Test" << endl;



you were comparing a character to a string.


edit: typo

[edited by - Tiffany_Smith on July 27, 2003 1:40:41 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!