Completely stuck can not understand

I am writing a program which shows how much tax credit is available at the end its suppose to show the amount you can get,

It does this but it also shows:
You are eligable for Working Tax Credits, Would you like to find out how much? (Y/N)

which is an answer further up in the program im a complete biginner see if you can spot what i have done wrong and help me please?

here is my code:
#include <iostream>
#include <conio.h>

using namespace std;

int age;
float wage;
char status;
float work;
char find1;




void main(void)
{
cout<<"Please enter your age or the oldest persons age if applying as a couple ";
cin>>age;

cout<<"What is your yearly wage(combined wages for a couple)? ";
cin>>wage;

cout<<"Are Your applying for working Tax credit as a couple?(Y/N) ";
cin>>status;

cout<<"How many hours do you work per week(person who works most hours for a couple)?";
cin>>work;

if(status='N')
{
if(age>25 && work>30 && wage<11700)
{
cout<<"You are eligable for Working Tax Credits, Would you like to find out how much? (Y/N)";
cin>>find1;
}

if(find1='Y')
{
if(wage<=8612)
{
cout<<"You are eligable for "<<char(156)<<"1180 ";
}

else if(wage>8613 && wage<11700)
{
cout<<"You are eligable for "<<char(156)<< "665";
}


}




if(status='Y')
{
if(age>25 && work>30 && wage<16300)
{
cout<<"You are eligable for Working Tax Credits, Would you like to find out how much? (Y/N)";
cin>>find1;
}

if(find1='Y')
{
if(wage<=8612)
{
cout<<"You are eligable for "<<char(156)<< "2880 ";
}

else if(wage>8612 && wage<11700)
{
cout<<"You are eligable for "<<char(156)<< "2370";
}

else if(wage>11700 && wage<12000)
{
cout<<"You are eligable for "<<char(156)<< "1630";
}

else if(wage>12000 && wage<14000)
{
cout<<"You are eligable for "<<char(156)<< "890";
}

else if(wage>14000 && wage<16300)
{
cout<<"You are eligable for "<<char(156)<< "150";
}
}


}
else
{
cout<<"You are not eligable for working tax credits";
}
}

getch();
}
Last edited on
closed account (3qX21hU5)
Alright first off when you post code on the forums please use the code tag feature (Hint the <> off to your right when replying). Makes the code much easier to see and read.

Second I'm not sure I understand your question. Your output is something it shouldn't be? Could you restate the question again so I can know what I'm looking for.

Since I didn't know what to look for I just did a quick scan and here are some things I noticed.


1) You are using void main(void). This is incorrect. main should also return a integer so this needs to be int main(). I would also recommend updating your compiler if it is not giving you a error for that. Since it is probably missing a lot of other things to.

2) You are using global variables when they are not needed.

1
2
3
4
5
6
7
int age;
float wage;
char status;
float work;
char find1;

void main(void)


All them variables will be global which means that any other function you might add to your program can change them by accident without you knowing. If you do have global variables use constant variables like const int MyVari; so that other functions cant change them.
To know more about this check out http://www.cplusplus.com/doc/tutorial/variables/

3) Your if statements are wrong. Your using the assignment operator if(status='N') when you should be using this if(status == 'N').

Didn't get all the way through your code since it was kinda hard to read without code tags but that's the main things that I saw.
Last edited on

As Zereo said, we can't read your code well, or tell how it's formatted if you don't use code tags.

Fixed all the issues I could find and left my debugging steps in so you could see what I did to fix it. Took longer than necessary because you didn't have code tags and your code wasn't formatted.

changed find1 and status to strings.
changed void main to int main
changed if(status='Y') (status == "Y")
changed if(find1='Y') (find1 == "Y")
and moved a } maybe more than one.

You need to change one of your if statements to include someone who is 25. Right now your using if(age>25) or if(age<25).

Your also using only upper case Y or N, so you might want to tell the user to enter in upper case or check for both Y and y.

I know it's messy because of all the // Test code, but that's all you need to do to fix most program issues. 1. format your code, 2. put in a few cout commands to test if your if statements are working.

My recommendation is in the future, write your program logic first, meaning your if/else/while statements. Once you get the logic working the way you want, then add the input/output/math.

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include <conio.h>

using namespace std;

int age;
float wage;
float work;
string find1;
string status;

int main(void)
{
     cout<<"Please enter your age or the oldest persons age if applying as a couple ";
     cin>>age;
     cout<<"What is your yearly wage(combined wages for a couple)? ";
     cin>>wage;
     cout<<"Are Your applying for working Tax credit as a couple?(Y/N) ";
     cin>>status;
     cout<<"How many hours do you work per week(person who works most hours for a couple)?";
     cin>>work;	

// Test
if (status == "Y")
{cout << " Y " << status << endl;}
else 
if (status == "N")
{cout << " N " << status << endl;}
else
{cout << " Unkn " << status << endl;}
// Test
if (age>25)
{cout << "age = " << age << endl;}
if (work>30)
{cout << "work = " << work << endl;}
if (wage<16300)
{cout << "wage = " << wage << endl;}

cout << age << " " << wage << " " << status << " " << work << endl;
     if (status == "N")
     {
// Test
cout << "Status = No" << endl;
          if(age<25 && work>30 && wage<11700)
          {	
          cout<<"You are eligable for Working Tax Credits, Would you like to find out how much? (Y/N)";
          cin>>find1;
          }

          if(find1=="Y")
          {
          if(wage<=8612)
          {
          cout<<"You are eligable for "<<char(156)<<"1180 ";
          }
          else 
          if(wage>8613 && wage<11700)
          {
          cout<<"You are eligable for "<<char(156)<< "665";
          }
     } 
     }
     if (status == "Y")
     {
// test
cout << "Status = Yes" << endl;
if (age>25)
{cout << age << endl;}
if (work>30)
{cout << work << endl;}
if (wage<16300)
{cout << wage << endl;}

          if(age>25 && work>30 && wage<16300)
          {
          cout<<"You are eligable for Working Tax Credits, Would you like to find out how much? (Y/N)";
          cin>>find1;
          }

          if(find1 == "Y")
          {
                    if(wage<=8612)
                    {
                    cout<<"You are eligable for "<<char(156)<< "2880 ";
                    }

                    else if(wage>8612 && wage<11700)
                    {
                    cout<<"You are eligable for "<<char(156)<< "2370";
                    }

                    else if(wage>11700 && wage<12000)
                    {
                    cout<<"You are eligable for "<<char(156)<< "1630";
                    }

                    else if(wage>12000 && wage<14000)
                    {
                    cout<<"You are eligable for "<<char(156)<< "890";
                    }

                    else if(wage>14000 && wage<16300)
                    {
                    cout<<"You are eligable for "<<char(156)<< "150";
                    }
          }

     else
     {
     cout<<"You are not eligable for working tax credits";
     }
     }

}
Topic archived. No new replies allowed.