Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,094 questions

40,775 answers

573 users

How to convert number of days to years, weeks and days in C++

1 Answer

0 votes
#include <iostream>

void print_ywd(int total_days) {
   int years, weeks, days, week_days = 7;
  
   years = total_days / 365;
   weeks = (total_days % 365) / week_days;
   days = (total_days % 365) % week_days;
  
   std::cout << "years = " << years << "\n";
   std::cout << "weeks = " <<  weeks << "\n";
   std::cout << "days = " <<  days << "\n";
}
  
int main() {
   int total_days = 398;
      
   print_ywd(total_days);
}
      
            
              
              
              
/*
run:
              
years = 1
weeks = 4
days = 5
           
*/

 





answered Sep 25, 2021 by avibootz
edited May 6, 2023 by avibootz

Related questions

2 answers 85 views
1 answer 37 views
1 answer 67 views
1 answer 50 views
50 views asked Jul 16, 2021 by avibootz
...