output problem

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
#include <iostream>
#include <conio.h>
using namespace std;

class complexos {
                double parteReal;
                double parteImaginaria;
      public:
                complexos();
                void setcomplexo(double, double);
                void adicao(complexos, complexos);
                void subtracao(complexos, complexos);
                void imprime(void);
};

complexos::complexos() {
     parteReal = 0;
     parteImaginaria = 0;
}

void complexos::setcomplexo(double r, double i) {
     parteReal = r;
     parteImaginaria = i;
}

void complexos::adicao(complexos c1, complexos c2) {
     parteReal = c1.parteReal + c2.parteReal;
     parteImaginaria = c1.parteImaginaria + c2.parteImaginaria;
}

void complexos::subtracao(complexos c1, complexos c2) {
     parteReal = c1.parteReal - c2.parteReal;
     parteImaginaria = c1.parteImaginaria - c2.parteImaginaria;
}

void complexos::imprime() {
     cout << "(" << parteReal << ", " << parteImaginaria << ")";
}

int main() {
    complexos complexo1, complexo2, complexo3;
    int i;
    double pr, pi;
    
    for (i = 0; i < 2; i++) {
        cout << "Entre com a parte real do numero complexo " << i + 1 << ": ";
        cin >> pr;
        cout << "Entre com a parte imaginaria do numero complexo " << i + 1 << ": ";
        cin >> pi;
        if (i == 0)
           complexo1.setcomplexo(pr, pi);
           else
               complexo2.setcomplexo(pr, pi);
        cout << "\n";
    }
    
    cout << "Numero complexo 1: " << complexo1.imprime();
    cout << "Numero complexo 2: " << complexo2.imprime();
    
    complexo3.adicao(complexo1, complexo2);
    cout << "Complexo 1 + Complexo 2 = " << complexo3.imprime() << endl;
    complexo3.subtracao(complexo1, complexo2);
    cout << "Complexo 1 - Complexo 2 = " << complexo3.imprime();
    
    getch();
    return 0;
};


there are some problems in the void imprime(void); function that I can't identify.
"What is your problem" consists of three parts:
What does not work?
What does happen?
What should happen?
I found the problem by myself here.
The line 57, 58, 61 and 63 weren't working because they were out putting a function that out puts. I think the problems is this.
Ah I see. No, the problem is that you were trying to output... nothing (void) here.
Topic archived. No new replies allowed.