yes , its from acdemic ..זה באמת תרגיל מבית הספר? אני חושב שראיתי את השאלה הזו בעבר במבחן המקוון של פירסון שהרבה חברות משתמשות בו כדי לסנן מועמדים פוטנציאליים לעבודת תכנות.
hi , thank you for answer.Of course we can hep but that doesn't mean doing your homework for you. If you would like us to help you then you need to come here with a specific issue and provide a FULL and CLEAR explanation of it. For a start, the title of the thread should be something meaningful that describes the issue. "Exercise" is pretty much useless. Your post should then contain ALL the relevant information and nothing irrelevant. Just posting a picture of your homework assignment is not nearly adequate. You need to explain exactly what you're trying to achieve, exactly how you're trying to achieve it and what happens when you try, including relevant code and error messages. If you have no idea how to do the whole thing then you need to go back and review what you have learned in your class/course because it's not for us to reteach you what you didn't listen to the first time. If there's some specific concept you're having trouble with then you need to specify exactly what that is. We're here to help and we're keen to do so but we're not here to be taken advantage of. You need to do your own homework but we will help you along the way, if you show that you're making the appropriate effort on your own behalf.
OK, this code line comes from the teacher.Lots of people say that their teachers are bad and many of them are, but it's hard to believe that your teacher is bad enough that you don't know how to declare variables or that you can't see that, based on the partial screenshot that you have provided, those variables are already declared and the data is already being read into them. It shouldn't be for us to teach you the absolute basics like that. I'd like to see some sort of effort on your part first. You still haven't given any indication that you have worked out the logic that the code needs to implement. You've obviously got some code to start with, although it seems that it's not your own, but you haven't shown us that properly, so we don't even know what you're starting from. If you post code, DO NOT post it as a picture. Post it as text and format it as code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int day = int.Parse(Console.ReadLine());
int month = int.Parse(Console.ReadLine());
int year = int.Parse(Console.ReadLine());
bool valid = false;
if (year >= 1901 && year <= 2099) {
valid = true;
}
else {
valid = false;
}
if (month >= 1 && month <= 12)
{
valid = true;
}
else {
valid = false;
}
switch (month) {
case 4: case 6: case 9: case 11:
Console.WriteLine("month {0} has 30 day", month);
break;
case 2:
Console.WriteLine("month {0} has 28 or 29 day", month);
break;
case 3: case 5: case 7: case 8: case 10: case 12:
Console.WriteLine("month {0} has 31 day", month);
break;
default :
Console.WriteLine("{0} is not a vaild month number", month);
break;
}
if (day >= 1 || day <= 31)
{
valid = true;
}
else {
valid = false;
}
if (valid)
{
Console.WriteLine("The date {0}-{1}-{2} is valid", day, month, year);
}
else {
Console.WriteLine("The date {0}-{1}-{2} is not valid", day, month, year);
}
}
}
}
valid
to false, but later overwrite it with true. Also you don't seem to be checking the number of days for specific months. Yes, you are reporting to the user the number of days for that month (except Jan for some reason), but you are not actually validating the day to be within that month's range.