C/C++ C++ kodunda hata nerede?

SubhanXd

Centipat
Katılım
5 Kasım 2022
Mesajlar
151
Selamlar.Yapmam gereken görev :
Given two real numbers X and Y, apply the specified transformations based on the conditions: If X and Y are negative, replace each value with its absolute value. If only one of them is negative, increase both values by 0.5. If both values are non-negative and do not belong to the range [0.5, 2.0], reduce both values by 10 times. Otherwise, leave the numbers unchanged.
Yazdığım kod:
int main(){
double x , y ;
cin >> x ;
cin >> y ;
if (x < 0 and y < 0) {
cout << abs(x) << " " << abs(y) << endl ;
} else if ((x || y < 0) || (x || y > 0)) {
cout << x + 0.5 << y+0.5 << endl ;

}else if ((x > 0 and y > 0) and ( x >2 and y > 2 )) {
cout << x / 10 << " " << y / 10 << endl ;
} else {
cout << x << " " << y << endl ;
}

}
 
Son düzenleyen: Moderatör:
Hocam o abs ( y ).Neden burada öyle gözüküyor anlamadım.
C++:
int main(){
   double x , y  ;

   cin >> x ;
   cin >> y ;

   if (x < 0 and y < 0) {
    cout << abs(x) << " " << abs(y) << endl ;
   }  else if ((x || y < 0) || (x || y > 0)) {
      cout << x + 0.5 << y+0.5 << endl ;
  
}else if ((x > 0 and y > 0) and ( x >2 and y > 2 ))  {
   cout << x / 10 << " "  <<  y / 10 << endl ;
}  else {
   cout << x << " "  << y << endl ;
}
 
}
 
C++:
int main(){
   double x , y  ;

   cin >> x ;
   cin >> y ;

   if (x < 0 and y < 0) {
    cout << abs(x) << " " << abs(y) << endl ;
   }  else if ((x || y < 0) || (x || y > 0)) {
      cout << x + 0.5 << y+0.5 << endl ;
 
}else if ((x > 0 and y > 0) and ( x >2 and y > 2 ))  {
   cout << x / 10 << " "  <<  y / 10 << endl ;
}  else {
   cout << x << " "  << y << endl ;
}
 
}
En üste bunları ekle, çalışıyor

#include <iostream>
using namespace std;
 
C++:
else if ((x || y < 0) || (x || y > 0))

C++'ta karşılaştırma böyle çalışmıyor (syntax olarak bir hata yok ama düşündüğünüz gibi çalışmaz.).

Kod:
else if ((x > 0 || y < 0) || (x < 0 || y > 0))
// -------^^^^^---------------^^^^^

@SubhanXd acaba bunu mu kastettiniz?
 
Son düzenleme:

Yeni konular

Geri
Yukarı