0
Why is there a need of spaces and colon in c++ while outputing values with relavent string text?
I made a relatively simple code with call by reference to change values and the print them with relavent text. My Code: https://www.sololearn.com/compiler-playground/czEzceY30TmN Expected Output: values are DD/MM/YY28 / 12 / 2022 Actual Output: values are DD../Playground/
1 Odpowiedź
+ 1
#include <iostream>
#include <cctype>
using namespace std;
int stringnumtoint(string &dd){//numberinstringtoint converter
int res = 0, *n = new int;
*n = dd.length();
for(int i = 0; i <= *n ; i++){
res = (i + 1 <= *n)? res*10 + (dd[i] - 48): res;
}
delete(n);
return res;
}
string Date(int *DD,int *MM, int *YY){
string day = "28", month = "12", year = "2022";//date in string
*DD = stringnumtoint(day);
*MM = stringnumtoint(month);
*YY = stringnumtoint(year);
string res = day + " / " + month + " / " + year; //1
return res;
}
int main() {
int DD , *MM = new int, *YY = new int;
DD = *MM = *YY = 0;
//string Date(int DD, int MM, int YY); // 2
cout << "Date in EU format( DD / MM / YY) : " << flush;
//function called
cout << Date(&DD,MM,YY) <<endl; //3
cout<< "values are DD/MM/YY : "<<flush;
cout<< DD<<'/'<<*MM <<'/'<<*YY<<endl;
return 0;
}