if statement - if statment not printing code in c -
#include <stdlib.h> #include <time.h> #include "stdio.h" int main(int argc, char const *argv[]) { int money; int safety; int health; int happiness; int question; int anwser; anwser = 0; unsigned int iseed = (unsigned int)time(null); srand(iseed); printf("welcome mayor\n\ni hope new seat here\n\nyour days packed full of questions must anwser simpy y/n\n"); printf("oh @ that, first customer ready\n"); printf("oh watch out resources dont let them low or empeached dun dun dun\n\n"); question = rand() % 3 + 1; switch (question) { case 1: printf("hey mayor,can build swimming pool?\n1. yes\n2.no\n"); scanf("%d",anwser); if (anwser == 1)//**this problem starts** { printf("thanks mayer!\n"); happiness ++; money --; } else { printf ("):\n"); } break; case 2: printf("hey mayor, can run fundraiser hospitals\n1. yes\n2.no\n"); scanf("%d",anwser); if (anwser == 1)//other problem here { printf("best mayor ever\n"); health ++; } else { printf("ugh\n"); } } return 0; }
so im not sure going on here if statment not want exectue thr code within {} im begginer c programmer typographical error, apprecciated. you.
read scanf()
's documentation,
scanf("%d", &anwser); // ^ address of operator (you must pass pointer // variable's // address)
and also, should check return value ensure input valid , answer
initialized input data.
Comments
Post a Comment