mercredi 20 octobre 2021

Hi, I' m new, I did a test today on c++, and there were this exercise, is it wrong? [closed]

The teacher say that whenever the c value is negative it say: " the a number is negative" but it doesn't make sense.

Is the program written in the wrong form?

In my opinion else should be part of the if(a>0) with {} i don t know why he choose to not use it.

In conclusion, is the correct form like: if(a>0){...}else and than cout?

#include <iostream>`

using namespace std;

int main(void) {

  int a, b, c;
  cin >> a;
  cin >> b;
  cin >> c;
  if (a > 0)
    if (b > 0)
      if (c > 0)
        cout << "they are all positive";
      else
        cout << "the number a is negative";
}

Aucun commentaire:

Enregistrer un commentaire