-3

In this code the output is 'r' instead of 'r0'

Instead of doing the operations it outputs me the first 'r' (equals 100) and does not do the process. I´m trying to program an operation like (x_0 = x + (nt²/(2(x+(n(t-1)²/2(x+(n(t-3)²/2(x + (n(t-4)²...)²)²)²)²)²)²)²)²) in where the process is repeated until the variable 't' is '0'(because each time the operation is done 't' get a '-1').

#include <iostream>
#include "math.h"
using namespace std;
int operation(float r,
float r0,
float recursiva,
float operacion,
float recursivaPrincipal2,
float recursivaPrincipal,
float p,
float n,
long long t,
float q,
float potenciaQ,
float c,
float potenciaC,
float t2,
float division);

float r = 100;
float t = 10000;
float r0;
float recursiva;
float operacion;
float recursivaPrincipal2;
float recursivaPrincipal;
float p;
float n;
float q;
float potenciaQ;
float c;
float potenciaC;
float t2;
float division;

int main() {
    r0 = r + operacion;
    potenciaQ = pow(10,10);
    q = 6 * potenciaQ;
    potenciaC = pow(10,2);
    c =  5 * potenciaC;
    while (t = 10000, t = t - 1, t > 0) {
        t2 = t * t;
        n = q * t2;
        operacion = n / recursivaPrincipal;
        recursivaPrincipal2 = recursiva * recursiva;
        recursivaPrincipal = 2 * recursivaPrincipal2;
        recursiva = r + operacion;
        if (t == 0) {
            system("pause");
            return 0;
        }
        cout << "Solucion: " << r0 << endl;
    }
}

i want to do something like this

I'm so sorry if this code offended you (comments look like it) but I'm not very good, this is my first c++ code (and last I think)

  • 4
    A function that takes fourteen arguments is almost certainly wrong. And having global variables with the same names as those arguments is also almost certainly wrong. But that function isn’t defined or called, so it doesn’t affect this code. – Pete Becker Mar 10 '19 at 20:34
  • 1
    I doubt this does what you think it does `while (t = 10000, t = t - 1, t > 0) {`. Seems like what you are looking for is `for (t = 10000; t > 0; t = t - 1) {` – john Mar 10 '19 at 20:35
  • Please indent the code, so it is readable; get rid of global variables; don't pass so many parameters (maybe define a struct); use meaningful names, not p,n,q,t2; it's confusing to have both `operation` and `operacion` – Michael Veksler Mar 10 '19 at 20:36
  • That `while` loop is definitely wrong. `t = 1000` sets `t` to 1000. Okay so far. `, t = t - 1` now sets `t` to 999. And finally `, t > 0` will always be true, because the value of `t` is 999. – Pete Becker Mar 10 '19 at 20:37
  • My eyes! The goggles do nothing – Sylwester Mar 10 '19 at 20:38
  • Even if the loop is fixed, your solution which is in r0 is never updated inside the loop or after the loop so what does the loop do then ? – mujjiga Mar 10 '19 at 20:39
  • I'm new to this, sorry, but this if my first code in C++ – Álvaro d'Ors Mar 11 '19 at 16:11
  • @PeteBecker i want to do an operation to do (for example setting 't' as 10) t(now is 10)/(something + (t(now 9)/(something+(t(now 8)...(and repeat the process until we have 't' = 0))²)² – Álvaro d'Ors Mar 11 '19 at 16:15
  • That's probably a `for` loop, not a `while` loop. `for (t = 1000; t > 0; t = t - 1)`. – Pete Becker Mar 11 '19 at 16:43
  • @PeteBecker I have re-wrote the code, want to see it? – Álvaro d'Ors Mar 11 '19 at 17:06
  • By the way @PeteBecker how can I do a loop like: for (t = 1000; t > 0; t--) that makes t=999, then 998, 997, 996, 995, 994, 993, ...? – Álvaro d'Ors Mar 11 '19 at 17:12

1 Answers1

0

The answer is based on what i get from your question

Please do expand your mathematical expression for t=3 and append an image of it

by far what i got from your expression you need this

float func(int t,int n,int x)
 {
  if (t==1)
  {
   return (x + (n/2)*(n/2)) * (x + (n/2)*(n/2));
  }

  return x + (n*t*t)/(2*func(t-1,n,x)) ;
 }

According to the picture you have uploaded this is my code

Don't use 0 for n

#include<iostream>

using namespace std;

double partSolver(int x,int p, int n)
{
   if(n==0)  return 2*x*x;
   double val = x - ( (p*n*n) / partSolver(x,p,n-1) );
   return 2*val*val ;
}

double solver(int x,int p,int n)
{
   return (n*n * 2) / partSolver(x,p,n-1);
}

int main()
 {
  cout<<"The Solution is: "<<solver(3,2,1)<<endl;

  return 0;
 }