I need a good direction and a advice.

I'm trying to write a code that will give me two solutions one for x and one for y.

The equation is the following x^2+4=y^3


The solution for y is y=(x^2+4)^1/3


The solution for x is x=(y^3+4)^1/2


The answer needs to printed like that in upper section.
I've written a bad code, cause I'm not good at programing. But never the less
it's a start, i think.

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

#include <iostream>

using namespace std;

int main () {

    int a; //replaceable
    int b; //replaceable

    int ind_a=2; //upper index of a
    int ind_b=3; //upper index of b
    int equation = a;
    int d_unk; //desired unknown

    int rp_1 = 'x'; //replaceable_1
    int rp_2 = 'y'; //replaceable_2


    do {
    cout<<"For which uknown do you want the answer of the : " << equation << "(x or y)?"<<"\n"<<"Uknown: ";
    cin>> d_unk;

    if (d_unk!='x' || d_unk!='y'){

        cout<<"Uknown is not part of the equation"<<endl;

        }

    }while(d_unk!='x' || d_unk!='y');

    if(d_unk== 'x') {

    equation = (a = (b^ind_b+4)^1/ind_a);

    cout<< "Answer for " << d_unk << "unknown is " << equation;}

    else {


        if(d_unk=='y')

        equation = (b = (a^ind_a+4)^1/ind_b);

    cout<< "Answer for " << d_unk << "unknown is " << equation;
    }

    return 0;

}

}


The code is generally bad, but I would appreciate any suggestions for what to do about it.
First of all you should make sure that your code works correctly.
1) ^ operator is binary xor, not power. You should use pow() function or just multiply argument by itself (several times).
2) 1/ind_a is equals to 0 because integer division is happening here. You should make one of the operands double to force compiler to use floating point division. Either declaring ind_a/ind_b as double or using constant 1 as 1.0 will do this.
Topic archived. No new replies allowed.