Help.

So, I am going to create a progam that will display the family category using a function. I made a code but when I enter a number, it always display as 1 as the output. I dont really know how void works.

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
#include <iostream>
#include <conio.h>
using namespace std;
void poor ();
void middleClass ();
void rich ();
int main()
{
    int income;
    cout<<"Enter family's monthly income: ";
    cin>>income;
    if (income <= 3000){
        cout<<poor;
    }
    if ((income >= 3001) && (income <= 20000)){
        cout<<middleClass;
    }
    if (income >= 20001){
        cout<<rich;
    }
    return 0;
}
void poor (){
    cout<<"Family is Poor. \n";

}
void middleClass (){
    cout<<"Family is Middle Class. \n";

}
void rich (){
    cout<<"Family is Rich. \n";

}


void means a function returns nothing.

Lines 13,16,19: You can't cout a void (nothing). Use a simple function call instead.
1
2
  // Line 13
  poor();

Thanks.
Topic archived. No new replies allowed.