Click here to Skip to main content
14,084,501 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
main()
{
char c;
printf("enter y for yes and n for no \n");
scanf("%c",&c);
if(c=='y')
 {
execute some statements

}
else
{
some statements
}
}
Posted
Updated 3 days ago
v3
Comments
Prerak Patel 17-Oct-11 8:02am
   
Not a question. Read some books, do Google and do it on your own.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You'll have to take input from user in JS prompt then do some thing like this in PHP

echo("Enter Y for yes and N for no")

if(//prompt value here == "Y")
//statement
else

//statement
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

php dose not have a console to enter user input it just work under server side web page
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

If you want to run php in the console has a simple solution that works from version 4 of php until today (my version is 7.2) that is the readline.
Unfortunately he needs the user to press enter after typing
$c = readline("Enter y for yes and n for no and press enter to confirm\n");
$c = strtolower($c);
if ($c == 'y' || $c == 'yes' ) {
    echo 'You chose yes' . PHP_EOL;
} else {
    echo 'You chose no [' . $c . ']' . PHP_EOL;
}
echo 'exiting program...' . PHP_EOL;


You can also use the stream_get_line function
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190518.1 | Last Updated 15 May 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100