localtimeを使用して現在の日付を取得し、その後、ユーザーから日数を取得し、追加後の日付(月および日)を計算する将来の日付計算機を作成していますC++ int値を使用して日付を取得する方法
ここで、tm_mon/tm_mdayを適切に使用できるように、newDateのint値を使用して問題が発生しています。
unsigned int newDate;
if (userInput > (365 - getDayOfYear())){ //If the intial date is greater than userInput
newDate = (userInput - (365 - getDayOfYear()));
cout << newDate << "\n";
}
else if (userInput < (365 - getDayOfYear())) { //If the intial date is less than userInput
newDate = (getDayOfYear() + userInput);
cout << newDate << "\n";
time_t rawtime = NewDate; // The problem is over here
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
cout << "The date is ";
cout << monthArray[timeinfo->tm_mon] << " " ;
cout << dayArray[timeinfo->tm_mday] << "\n";
代替手段はありませんか?
そして、あなたが苦しんでいる問題は何ですか?編集:さて、あなたはいくつかのコードをランダムに追加しました。ブレースはバランスが取れず、変数名は同じではありません。あなたは実際の問題が何であるかを言う必要があります。どのようにあなたの期待された出力とは異なる実際の出力が良いスタートです。 –