I don't know what I'm doing wrong...

I have an assignment in which I basically just have to take an old program, and rewrite it using functions, but it's proving to be rather difficult for whatever reason. Every time I fix one issue, I encounter another.
Right now, all my if statements are coming back with the error "expected a declaration", which i've made.
Can anyone see what i'm doing wrong?

#include <iostream>
#include <cmath>
#include <string>
using namespace std;

string name;
int age, week, select=0, percent, retire, yearsLeft, nowToRetire, retireSave=0, counter=0, retireSave2=0;
double savings, interest=.06;
double savingsNow, savingsFar=0, annualSave, totalInterest=0, n, wr, pmt;

// calculate retire age

if ( age >=60)
retire= 65;
if ((age >= 50) && (age <60))
retire= 67;
if ((age >=40) && (age <50))
retire= 70;
if (age < 40)
retire = 72;
I don't think the problem is with this piece of the code. Could you post more of it?

Edit: You might have scope issues with the variable age and/or retire. If all of those variables are global then I must say that is really bad practice.
Last edited on
ERROR output is normal, as it says: "where is age declared??"

age has no value.
how would if statement check the value if there is no value to check :)
1
2
3
// Calculate retire age
cout << "Please enter an age: ";
cin >> age;


Add those two lines of code and the console will ask you to input age and it will use that value for the if statement. Right now the code you just posted has no value for age (should get a warning, not an error) but in any case the program either won't work or won't work right.
Topic archived. No new replies allowed.