InterviewSolution
| 1. |
Solve : why won't my if-else statement work?? |
|
Answer» #include are you supposed to have ; at the end of an if statement? (if (9 = x) { not if (9= x); {) No. What language? Quote from: Geek-9pm on October 10, 2009, 01:30:55 PM What language? Sort of looks like C I think Code: [Select]#include <stdio.h> Code: [Select]#include <stdio.h> #define p printf #define s scanf int year, month, age, currentdate, currentmonth, birthmonth, birthdate, numofmonths, daysalive; main () { p("Welcome to my age calculating program!\n"); p("The program will calculate the number of days you have live since birth.\n"); p("Note: The result will not be exact because of leap years.\n"); p("Input age: ", age); s("%d;", &age); { for (currentmonth = 1; currentmonth <= 12; currentmonth++) p("%d \n", currentmonth); } p("Input current month: ", currentmonth); s("%d;", ¤tmonth); p("Input current date: ", currentdate); s("%d", ¤tdate); p("Input birth month: ", birthmonth); s("%d", &birthmonth); p("Input birth date: ", birthdate); s("%d", &birthdate); if (currentmonth >= birthmonth) { daysalive = (age * 365) + (currentmonth - birthmonth) * 30 + (30 - birthdate) + currentdate; p("The number of days you have lived is about %d", daysalive); s("%d", daysalive); } else (currentmonth <= birthmonth); { daysalive = (age * 365) + (12 - birthmonth) * 30 + (currentmonth * 30) + (30 - birthdate) + currentdate; p("The number of days you have lived is about %d", daysalive); s("%d", daysalive); } } modified it, got rid of ; on first if and it compiled FINE for me, what compiler are you using? |
|