#the first if statement is not working

18 messages · Page 1 of 1 (latest)

fierce duneBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

burnt sedge
#

you can't compare strings with == and !=

#

if you #include<string.h>, you can use a function called strcmp which takes two character pointers and returns
-1 if the first is lexicographical less than the second
0 if they are the same
1 if the first is lexicographical greater than the second

viscid flume
#

so what should i write exactly@burnt sedge

burnt sedge
#
//...
#include <string.h>
//...
if (strcmp(p_name, "NO") == 0)
//...
#

you may need to compare with "NO\n", I forget if scanning %s include the newline or not

viscid flume
#

@burnt sedge it did the oppsite.i was when i enter NO the program stop

burnt sedge
#

oh oops, != 0 instead of == 0

viscid flume
fierce duneBOT
#

@viscid flume Has your question been resolved? If so, run !solved :)

viscid flume
#

how do i keep prompting the user until the correct entry is made?

burnt sedge
#

something like this

int age;
do {
  prompt_user;
  user_input();
} while (valid_age);
viscid flume
#

so i should take out the if statement?

burnt sedge
#

your call, all I'm saying is that using a while loop to re-ask for input until a valid input is given is the most common way to do that

viscid flume
#

where should i put the do while in my program?

viscid flume
fierce duneBOT
#

@viscid flume

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. You can use !solved to close a post and mark it as solved.

viscid flume
#

!solved