need help

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;
}
I recommend using the modulus operator ( % ) to find the mod of age by ten. Lets say somebody is 37 years old. Doing 37 % 10 gives the result of 7. You can take it from here.

Eyenrique-MacBook-Pro:Desktop Eyenrique$ ./NextDecade 
Please enter your age: 23

Age: 23
7 years for next decade.
Eyenrique-MacBook-Pro:Desktop Eyenrique$ ./NextDecade 
Please enter your age: 32

Age: 32
8 years for next decade.


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
//NextDecade.cpp
//##

#include <iostream>
using std::cout;
using std::cin;
using std::endl;


int main(){


int age=0;
int temp;
int yearsForNextDecade=0;

cout<<"Please enter your age: ";
cin>>age;

temp=age; //we need an auxiliar variable to
        //hold age value;

while((temp%10)!=0){ //while mod of temp%10 is not 0 -zero-
        yearsForNextDecade++; //increment yearsForNextDecade + 1
        temp++; //increment age + 1      
}//end while                             

        //i.e. age=23    23%10=2.3  24%10=2.4
        //25%10=2.5     26%10=2.6
        //27%10=2.7     28%10=2.8
        //29%10=2.9     30%10=3 and mod -remainder- is 0 -zero-
        //exits the while loop;

cout<<"\nAge: "<<age<<endl;
cout<<yearsForNextDecade<<" years for next decade."<<endl;



return 0; //indicates success
}//end of main 
You can do it even easier than that.
age % 10 gives you the remainder when age is divided by 10, which is simply the last digit of age.
Knowing this, you can just do 10 - (age % 10) to give you the number of years until the next multiple of 10 (the next decade). (So if age is 37, then age % 10 will be 7 and 10 minus that will give you 3 years until the next decade.)
Topic archived. No new replies allowed.