Exercise

daniell

Member
Joined
Dec 8, 2021
Messages
5
Programming Experience
Beginner
Hi everyone,
I'm new at c# , I have a exercise but don't know when start from.. some help ?
 

Attachments

  • Screenshot_20211208-235840_Chrome.jpg
    Screenshot_20211208-235840_Chrome.jpg
    124.1 KB · Views: 19
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.
 
Is that really an exercise from school? I think I've seen that question before in Pearson's online test that a lot of companies use to screen potential candidates for a programing job.
 
As with any programming problem, you should start with the logic. How would you perform the task if you had to do it manually? Work out the steps involved and break them down until they are as simple as possible. Now you have an algorithm and you can implement it any way you want, be it in any programming language or otherwise. because the steps are so simple, each one will take 1-3 lines of code to implement. That means that they will generally be easy to implement and also easy to identify exactly which one is a problem if you get stuck. When you ask a question here, you should be able to show us your algorithm and explain which step you're stuck on.
 
זה באמת תרגיל מבית הספר? אני חושב שראיתי את השאלה הזו בעבר במבחן המקוון של פירסון שהרבה חברות משתמשות בו כדי לסנן מועמדים פוטנציאליים לעבודת תכנות.
yes , its from acdemic ..
 
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.
hi , thank you for answer.
i realy dont want you do my home wrok .
i new here and begginer of c#.
the teacher in class was bad unfortunately , and i need to learn own .
i dont know how to see the logic of the question , and with what to start ?
ho i define the int in this exercise.. thank for help
 
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.
 
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.
OK, this code line comes from the teacher.
I know how to declare variables , I will try it at the visual studio again and I up the lines to here . But I told you I really don't understand the logical of question. I hope to hint
 
exercise:
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);
            }
        }
    }
}
hi i try it but it not working , can hint me ?
 
Instead of just running your code (by pressing F5 in most key mappings), actually step through your code line by line with a debugger (by pressing F10 in most key mappings). Then you can see what the computer is doing as it executes what you have written.

As a hint, notice that some point you may have set 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.
 
Back
Top Bottom