Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 |
#include <stdio> //... int tag=0; int monat=0; int jahr = 0; scanf("%d.%d.%d",&tag,&monat,&jahr); //... |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
// Alter nach 100 Jahren.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung. // #include "stdafx.h" #include <iostream> #include <string> #include <ctime> using namespace std; int aktDay, aktMonth, aktYear; int DayA, MonthA, YearA; int DayB, MonthB, YearB; int DaysTo100; int DaysPersonA, DaysPersonB, SumDays; void DaysToDate (void) { //Hinzufügen von einzelnen Tagen auf das aktuelle Datum, um so Zukunftsdatum zu ermitteln while (DaysTo100 > 365) { aktYear++; DaysTo100 = DaysTo100 - 365; //cout << DaysTo100 << endl; } while (DaysTo100 > 31) { switch (aktMonth) { case 1: case 3: case 5: case 7: case 8: case 10: { aktMonth++; DaysTo100 = DaysTo100 - 31; break; } case 4: case 6: case 9: case 11: { aktMonth++; DaysTo100 = DaysTo100 - 30; break; } case 2: { aktMonth++; DaysTo100 = DaysTo100 - 28; break; } case 12: { aktMonth = 1; aktYear++; DaysTo100 = DaysTo100 - 31; break; } } //cout << DaysTo100 << endl; } while (DaysTo100 > 0) { if ((aktMonth == 2) && (aktDay == 28)) { aktMonth++; aktDay = 1; DaysTo100--; } else if (aktDay == 30) { switch (aktMonth) { case 4: case 6: case 9: case 11: { aktMonth++; aktDay = 1; DaysTo100--; break; } } } else if (aktDay == 31) { switch (aktMonth) { case 1: case 3: case 5: case 7: case 8: case 10: { aktMonth++; aktDay = 1; DaysTo100--; break; } } } else if (aktDay == 31) { if (aktMonth == 12) { aktYear++; aktMonth = 1; aktDay = 1; DaysTo100--; } } else { aktDay++; DaysTo100--; } //cout << DaysTo100 << endl; } } int From0ToDate (int DayF, int MonthF, int YearF) { //cout << ((YearF * 365,2422) + (MonthF * 30,4166) + DayF); return ((YearF * 365.2422) + (MonthF * 30.4166) + DayF); } int main (void) { //aktuelles Datum holen time_t date = time(NULL); tm* current_date = gmtime(&date); //Datum in Variablen speichern aktYear = current_date->tm_year + 1900; aktMonth = current_date->tm_mon + 1; aktDay = current_date->tm_mday; cout << "aktuelles Datum: " << aktDay << "." << aktMonth << "." << aktYear << endl; cout << "-------------------------------------------------------------------------------" << endl; cout << "Geburtstag der Person A eingeben: "; cin >> DayA; cout << "Geburtsmonat der Person A eingeben: "; cin >> MonthA; cout << "Geburtsjahr der Person A eingeben: "; cin >> YearA; cout << "Geburtstag der Person B eingeben: "; cin >> DayB; cout << "Geburtsmonat der Person B eingeben: "; cin >> MonthB; cout << "Geburtsjahr der Person B eingeben: "; cin >> YearB; cout << "-------------------------------------------------------------------------------" << endl; cout << "Geburtstag A: " << DayA << "." << MonthA << "." << YearA << endl; cout << "Geburtstag B: " << DayB << "." << MonthB << "." << YearB << endl; DaysPersonA = From0ToDate (DayA, MonthA, YearA); DaysPersonB = From0ToDate (DayB, MonthB, YearB); cout << "DaysPErsonA " << DaysPersonA << endl; cout << "DaysPErsonB " << DaysPersonB << endl; SumDays = DaysPersonA + DaysPersonB; cout << "SumDays: " << SumDays << endl; SumDays = 36524 - SumDays; if (SumDays < 0) cout << "Berechnung nicht möglich, Sie sind schon über 100 Jahre zusammen alt." << endl; else { DaysTo100 = SumDays / 2; DaysToDate (); cout << "Sie werden am " << aktDay << "." << aktMonth << "." << aktYear << " 100 Jahre alt." << endl; } cin.get (); cin.get (); return 0; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
#include <iostream> #include <iomanip> #include <ctime> int main() { std::tm date; std::cin >> std::get_time(&date, "%d.%m.%Y"); return 0; } |
deine eigentliche Frage? Weil im letzteren ists ja eig nur Tage durch 365 teilen...Zitat
Sie werden also in 1081 Tagen zusammen 100 Jahre, aber wann ist das?
Werbeanzeige