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;
}
This probably should be in the C++ section of the site. But I see a few problems with your code.

First try using code tags like this

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
#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;
} 


Now the problems I see are:

* Delete line 1. You don't need #include "stdafx.h" . That is a C header file and you are writing in C++

* Rewrite your main function to look like this int main() and delete array<System::String ^> ^args

*On line 16 you should probably declare decadesage as a float type then divide by 10.0. Adding the .0 to a number tells the compiler to treat the number as a float then you should be able to figure out how to use the decimal places to figure out how many years remain until a person is another decade older.

*on line 23 you need to include a << in front of the "Right now you are in decade"
Last edited on
Thanks, still can't figure out for the life of me how i would write it. Only my second class.

Garion wrote:
Now the problems I see are:

* Delete line 1. You don't need #include "stdafx.h" . That is a C header file and you are writing in C++

* Rewrite your main function to look like this int main() and delete array<System::String ^> ^args


Wrong, the OP is using C++/CLI, which is NOT C and is NOT C++ either.

stdafx.h is NOT a specific C file either, it is usually used for precompiled headers.
Topic archived. No new replies allowed.