6970 Shares

Topic: **Case string c#****Question:**
I have three ints: d, m and y which store the day, month and ,year respectively of a person's date of birth. How can I create a string using these three variables to output their birthday?
For example, their birthday is January 1st, 2000. So d = 1, m = 1, and y = 2000.
How can I pass these into a function which then forms the string "1/1/2000" and returns that as their date of birth?

November 20, 2019 / By Airlia

In the following code you also can find some number formatting in case - deviating from your assignment - you want to have a date like 01/01/2000. This is also to stress the flexibility of stringstream. #include

👍 122 | 👎 7

Did you like the answer? We found more questions related to the topic: **Case string c#**

Guys, don't waste memory. public static String sort(String s) { if (s.length()==1) return s; char lowestChar = s.charAt(0); int lowestCharIndex = 0; for (int i = 1; i < s.length(); i++) if (s.charAt(i) < lowestChar) { lowestChar = s.charAt(i); lowestCharIndex = i; } return lowestChar + sort(s.substring(0, lowestCharIndex) + s.substring(lowestCharIndex + 1)); }

I usually use a stringstream to work with numeric values and string values. Eg: #include

👍 40 | 👎 6

Suppose, you have as ur example: // start of code #include

👍 34 | 👎 5

stringstream, as already mentioned: std::string make_date(int d, int m, int y) { std::ostringstream os; os << d << '/' << m << '/' << y; return os.str(); }

👍 28 | 👎 4

You can use integer division (\) note the left leaning slash and MOD (modulo) division. (See Note below for C) Integer division only returns an integer without any remainder MOD returns only the remainder of a division Regular division for example 10/3 = 3.33333 Integer Division 10\3 = 3 Modulo 10 MOD 3 = 1 For today 1 April 2008 your integer YYYYMMDD is 20080401 To extract the year perform integer division 20080401 \ 10000 = 2008 save this result in your year variable recover the mmdd 20080401 mod 10000 = 401 (the remainder) now repeat the above extraction proceedure but using the mmdd remainder 401 \ 100 = 4 save as month 401 mod 100 = 1 save as day ***** NOTE : ******* The modulo operator in C is % In C the / division operator is used for integer division when dividing one integer by an other (NO Type casting) the result will be an integer even if the result is a real number EDIT: IQBAL brings up a valid point about the size of the INT value ONLY if you use an UNSIGNED SHORT integer which is limited to the value of 65535. An unsigned LONG integer can hold a value of 4,294,967,295 which is large enough to hold your date code. Since you specifically asked about processing an integer as a custom date code it is assumed that you know about variable types. For those who don't here's a list of INT types and there numeric values they may hold. unsigned short int 0 to 65535 short int -32768 to 32767 unsigned long int 0 to 4294967295 long int -2147483648 to 2147483647

If you have your own answer to the question case string c#, then you can write your own version, using the form below for an extended answer.