Hello ,
I've been working for an hour now searching for a solution for a problem i have for tomorrow's workshop so I wanted to be ready for it and here was the question :
Write a program that reads 3 integers. Then, display:
The count of positive integers followed by the following text: positive integers are entered
The count of negative integers followed by the following text: negative integers are entered
The following picture shows a sample output of your program:
so I wrote the following code , but i was wondering if there was a simplest way to do it , because I can never make it like that if i had like 10 integer instead of 3 so I am aware my way of writing the code isn't the best , please any suggestions ?
(ps: so far we learned the following , cin and cout , if statement , if.. else statement , and the logical operators )
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cout << "enter 3 integers : ";
cin >> a >> b >> c;
if (a > 0 && b > 0 && c > 0)
cout << "3 numbers are positif \n 0 numbers are negatif \n";
if (a > 0 && b > 0 && c < 0)
cout << "2 numbers are positif \n 1 numbers is negatif \n";
if (a > 0 && b < 0 && c > 0)
cout <<"2 numbers are positif \n 1 numbers is negatif \n";
if (a < 0 && b > 0 && c > 0)
cout << "2 numbers are positif \n 1 numbers is negatif \n";
if (a > 0 && b < 0 && c < 0)
cout << "1 number is positif \n 2 numbers is negatif \n";
if (a < 0 && b < 0 && c > 0)
cout << "1 number is positif \n 2 numbers is negatif \n";
if (a < 0 && b > 0 && c < 0)
cout << "1 number is positif \n 2 numbers is negatif \n";
if (a < 0 && b < 0 && c < 0)
cout << "0 numbers are positif \n 3 numbers is negatif \n";
system("pause");
return 0;
}]