D
D
DAN_ON2020-11-05 15:42:23
C++ / C#
DAN_ON, 2020-11-05 15:42:23

Why does my attachment x not change always 1 does not work?

I have a task, you can see in the photo what needs to be solved through the x cycle and, that is, in the cycle they should increase in steps, here is the code and photo of the task5fa3f329d85a5580205691.png

#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main() {
float a =2.0;

float y;
float x=1.0;

for(;x<8; x+=0.5){
while(a<10){





a++;
}





    if(a>x){
float y=pow(a,2)+x;
printf("y=%f a=%f\n x=%f \t",y,a,x);
}
else if(a==x){
    float y=a*a;
    printf("y=%f a=%f\n x=%f \t",y,a,x);
}
else if(a<x){
    float y=(a*a)-x;
    printf("y=%f a=%f\n x=%f \t",y,a,x);
}
    
    
    
    
}


    
    
    
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
raster, 2020-11-07
@Rastr_0

#include "pch.h"
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main()
{
  float a = 2; 
  float x = 1;
  for (; x <= 8; x += 0.5) 
  {
    if (a > x)
      cout << a * a + x << "\n";
    else if (a == x)
      cout << a * a << "\n";
    else
      cout << a * a - x << "\n";

    if (a < 10)
      a++;
  }
}

Only here the task is a little strange, only the first condition is always fulfilled. Obviously x will always be less than a

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question