Posted By

kemikazii on 11/27/15


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

snima


Date Checker


 / Published in: C++
 

Asks the user for a date and then prints out the exact date 7 days from the user's date

  1. #include<iostream>
  2. using namespace std;
  3.  
  4. struct dat{
  5.  
  6. int day;
  7. int month;
  8. int year;
  9. int fday;
  10. int fmonth;
  11. int fyear;
  12.  
  13.  
  14.  
  15. };
  16.  
  17.  
  18. int main(){
  19.  
  20. dat test;
  21.  
  22. cout<<"\nPlease enter a date\n";
  23.  
  24. cin>>test.day;
  25. while(test.day>31||test.day==0){
  26. cout<<"That date is invalid. Please enter a valid date\n";
  27. cin>>test.day;
  28. }
  29.  
  30. cout<<"\nPlease enter a month\n";
  31. cin>>test.month;
  32. while(test.month>12||test.month==0){
  33. cout<<"That month is invalid. Please enter a valid month\n";
  34. cin>>test.month;
  35. }
  36.  
  37. cout<<"\nPlease enter a year\n";
  38. cin>>test.year;
  39.  
  40.  
  41.  
  42.  
  43. if(test.month == 4||test.month == 6||test.month==9||test.month==11){
  44.  
  45. if(test.day>=24){
  46.  
  47. test.fday=(7-(30-test.day));
  48.  
  49. if(test.month==12){
  50. test.fyear=test.year+1;
  51. test.fmonth=1;}
  52.  
  53. else test.fmonth=test.month+1;
  54. test.fyear=test.year;
  55.  
  56.  
  57.  
  58. }
  59.  
  60. else test.fday = test.day+7;
  61. }
  62.  
  63. else if(test.day>=25){
  64.  
  65. test.fday=(7-(31-test.day));
  66. if(test.month==12){
  67. test.fyear=test.year+1;
  68. test.fmonth=1;
  69.  
  70.  
  71. }
  72.  
  73. else test.fyear=test.year;
  74.  
  75.  
  76.  
  77. }
  78.  
  79. else test.fmonth=test.month+1;
  80.  
  81.  
  82.  
  83. cout<<"\n\n"<<test.fday<<"/"<<test.fmonth<<"/"<<test.fyear<<endl;
  84.  
  85.  
  86.  
  87.  
  88.  
  89. system("pause");
  90.  
  91. return 0;
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. }

Report this snippet  

You need to login to post a comment.