condicionales

Hola necesito modificar el siguiente código, para que cuando x sea > que 0 el programa sume, y cuando x sea < 0 el programa tendrá que restar.

este es el código para modificar:



#include <iostream.h> //---Permite las entradas y salidas
#include <conio.h> //---Permite implementar la funcion getche

main()
{
float x,y,s;
cout << "Digite el primer número \n" ;
cin >> x;
cout << "Digite el segundo número \n";
cin >> y;
s=x/y;
if(y==0)
{
cout << "La división entre cero no está definida\n";
}
else
{
cout << "El resultado es "<< s << " \n";
}
getche();
}


Gracias por la ayuda.
No comment
Last edited on
suetam wrote:
Hello I need to modify the code below, so that when x is> 0 the program to add, and when x is <0, the program will subtract.

this is the code to modify:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# include <iostream.h> //--- allows inputs and outputs
# include <conio.h> //--- allows you to use getch

main ()
{
    float x, y, s;
    cout <<"Enter the first number\n";
    cin>> x;
    cout <<"Enter the second number\n";
    cin>> y;
    s = x / y;
    if (y == 0)
    {
        cout <<"Division by zero is not defined\n";
    }
    else
    {
        cout <<"The result is" <<s <<"\n";
    }
    getch();
}


Thanks for the help.


EDIT: Fixed a few translation bugs. Thanks ne555.

-Albatross
Last edited on
It should be 'add', no join. And the comments don't look well either. ¿Which translator did you use?
Google's. :/

I probably should have looked over the translation before posting it. Maybe I trusted Google's Spanish translator too much.

-Albatross
Seriously, google's translate was the best once. Until they gave people the permision to edit the dictionaries. That's the point where google did it's worst mistake. Sadly...
Topic archived. No new replies allowed.