Decades problem

Can't figure out how to write to tell someone who is a certain age what their next decade would be in a certain amount of years. ie. say is someone was 23, how would i write that in 7 years they would be in their 3 decade?



// HowOld.cpp : main project file.

#include "stdafx.h"
#include <iostream>
using namespace std;

int main(array<System::String ^> ^args)
{
// Have the user enter their age
cout << "Please enter your age and prepare to have your mind blown! ";
int age;
cin >> age;

// Tell them how old they will be in a year
int nextYear = age +1;

// Report to the user how many decades old they are Done with the entered age
int decadesAge = age /10;

// Report to the user how many more years until they reach the next decade


// Display results
cout << "In a year you will be " << nextYear << " WOW! YOU'RE OLD!\n"
"Right now you are in decade " << decadesAge << " of you life.\n";

return 0;
}
Please use code tags when posting
http://www.cplusplus.com/articles/z13hAqkS/

example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main()
{
	const int DECADE = 10;
	int age = 11;
	int tempInt = age;

	while (tempInt > 0 && tempInt % 10 != 0)
	{
		tempInt--;
	}

	tempInt += DECADE;

	cout << "If you are " << age << " you will be " << tempInt << " in " << tempInt - age << " years" << flush;

	cin.ignore();
	return 0;
}
int age = 13;

use modulo to find out how many years have already passed since the last decade: age % 10
(this will give you number 3 - it's the remainder of division 13 / 10)

and the only thing you have to do now is subtract the remainder (3) from number 10
---> result = 7
Last edited on
closed account (z05DSL3A)
"Right now you are in decade X of you life."

You might need to think about this. If you are, say 5 years old, what decade of you life are you in? It is different to how many decades you have lived.
Last edited on by Canis lupus
Topic archived. No new replies allowed.