• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /var/www/html/cnasolution/application/views/question.php
Line: 191
Function: _error_handler

File: /var/www/html/cnasolution/application/controllers/Questions.php
Line: 419
Function: view

File: /var/www/html/cnasolution/index.php
Line: 315
Function: require_once

int yes_or_no (void) {              //Funcion yes_or_no. Confirma si el usuario quiere salir del usuario despues de seleccionar la opcion "EXIT".     char opcion2;          fprintf (stdout ,"Has seleccionado "Exit".
");     fprintf (stdout ,"Are you sure you want to exit y/n?: 
");     fscanf (stdin ," %c", &opcion2);          if ((opcion2 == 'y') || (opcion2 == 'Y'))         {             fprintf (stdout ,"Ha seleccionado "Si".
");         valor = 0;         return valor;                  }              if ((opcion2 == 'n') || (opcion2 == 'N'))         {             fprintf (stdout ,"Ha seleccionado "No".
");         valor = 1;         return valor;                  }     else          {              fprintf (stdout ,"No ha seleccionado una opcion valida
");          valor = 1;         return valor;              } }  int main()  {     char opcion;     char opcion2;     char * APLICACION;     char caracter;     char caracterhl;     int valor;     int Date;     char *Name;     char *mensaje;     int edad;     FILE *ficheromensaje;          fprintf (stdout ,"Introduce una cadena: 
");     fscanf (stdin ,"%s", APLICACION);           fprintf (stdout ,"Introduce un caracter: 
");     fscanf (stdin ," %c", &caracterhl);          fprintf (stdout ,"Introduce un segundo caracter: 
");     fscanf (stdin ," %c", &caracter);          stripe (caracter);     headline (APLICACION ,caracterhl);     //Imprime la carĂ¡tula.     stripe (caracter);          do {         fprintf (stdout ,"R) Register for a patient
");         fprintf (stdout ,"S) Search for a patient
");         fprintf (stdout ,"D) Discharge a patient
");         fprintf (stdout ,"L) List patients by age
");          //Presenta el menĂº del programa.         fprintf (stdout ,"X) Exit the program
");         fprintf (stdout ,"Choose an option
");         fscanf (stdin ," %c" ,&opcion);                  switch (opcion) {             case 'R':             fprintf (stdout ,"R) Register for a patient
");             break;                          case 'S':              fprintf (stdout ,"S) Search for a patient
");             break;                          case 'D':             fprintf (stdout ,"D) Discharge a patient
");             break;                          case 'L':             fprintf (stdout ,"L) List patients by age
");              break;                          case 'X':                yes_or_no ();             if (valor = 0) {                 break;             }             else {                 valor = 1;                 continue;             }                          default:             fprintf (stdout ,"Opcion no valida
");             break;         }     } while (yes_or_no() == 1);          return 0; }  

The program asks the for a character, if it is X, it goes into the yes_or_no function, where it asks the user he if wants to exit, if the answer is Y or y, it gives valor the value 0 and returns this variable and if the answer is N or n or something else entirely, it gives valor the value 1 and returns the variable. Then, if the value of valor is 0, the program should end there, and if the value is 1, it shoud loop back to the menu (Right before the switch function), but the program doesnt end, no matter the answer to the yes_or_no function.

Download script demo [LINK]
Download script demo [LINK 2] Download script demo [LINK 2]
c

First you need to declare the valor inside the function int valor;. After that, your function returns a integer, but in your main you don't assign any variable to store the value of return, then you should do valor = yes_or_no();, and in the condition of do-while use the variable valor too

see demo
  • 0
Reply Report

as @Hss said, you have to declare the valor variable in the function.

In this part of your code you have to change the condition in the "IF". change this ->if (valor = 0) in this -> if (valor == 0)...

case 'X':        yes_or_no ();     if (valor == 0) {     break;     }     else {     valor = 1;     continue;     } 
demo
  • 0
Reply Report