My program kind of works, kind of doesn't

ppp
Last edited on
The answer is a char. The other input is integers. You could use int answer, since you do expect 1 or 0.

Formatted input is a bit tricky. Make your current code print the answer on line 50 to see whether you actually get 0 or 1.
Hey there! Congrats on starting with C++. If you don't mind, do you have any other programming experience? I ask because the structure of your program can be optimized a bit and with the way int works it will present any fraction as a whole number(is that intended?)
@keskiverto I can't seem to be able to run the do while loop if I replace char answer with int answer.

@rghrist23 Thanks :), I have done some Java and Javascript, but nothing too fancy. I'd say I'm more comfortable with C++ either way. And yes, that's intented.
Alright cool. If you replace char answer with int answer then the while check should be while (answer == 1). One option I would propose would be to take this code here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

   for (int i=1; i<=n; i++) {
             for (j=1; j<=n; j++) {
                    if (a[j] != 0){
                    if ((a[i] % a[j] == 0) && (j!=i)) {
                        for (k=1; k<=n; k++){
                            if ((i!=j) && (i!=k) && (j!=k) && ((a[j]*a[k]) == a[i])) {
                                found = true;
                                cout << "a(" <<k << ") = a(" <<i << ") / a(" <<j << ")" <<endl;
                                cout << "Or: " <<a[k] <<" = " <<a[i] << " / " <<a[j] <<endl;
                            }
                        }
                    }
                }
            }
        }

and consider changing it to
1
2
3
4
5
int a[];//the array of the user inputted numbers
//make a for loop that divides indexes with each other and puts result into
//a different array, uses a a set of logic rules and can avoid duplicates this way
//either nest the matching formula or make another for loop to compare the arrays
//also consider using std::vector and making your above code a function to help clear up main 

Last edited on
Topic archived. No new replies allowed.