Професионална програма
Loading...
LoshaPanda avatar LoshaPanda 10 Точки

Product sign{2} - C++ fundamentals

Извинете ме, но не мога да си намеря грешка. Може ли някой да ме поправи ако вижда такава ?

 

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {

	double n, n1, n2, k = 0;

	cin >> n >> n1 >> n2;

	if (n < 0){
		k++;
	}
	if (n1 < 0){
		k++;
	}
	if (n2 < 0){
		k++;
	}

	if (k == 1)
	{
		cout << '-';
	} else if (k == 2) {
		cout << '+';
	} else if (k == 3) {
		cout << '-';
	} else if (k == 0){
		cout << '+';
	}

}

 

Тагове:
0
C++ Programming
MartinBG avatar MartinBG 3910 Точки
Best Answer

Какво е условието на задачата? Без него няма как да разгадаем какво не работи ;)

Иначе, не виждам причина да се използва тип double за променливите - int изглежда по-удачен тип за начина, по кийто се използват тези променливи в кода. 

0
MartinBG avatar MartinBG 3910 Точки

LoshaPanda  - Кодът ти не покрива сценариите, когато едно или две от числата са 0 (по условие резултатът трябва да е "+", независимо от останалите числа).

0
LoshaPanda avatar LoshaPanda 10 Точки

Благодаря за помощта !

1
wernereegranad75 avatar wernereegranad75 0 Точки

This kind of problems in C++ really brings back a lot of memories, I really enjoyed studying this language but I am only on the basics because it gives me headaches when trying to learn the Intermediate level of the course that I purchase on Udemy. I hope that you already figured out what's wrong with your codes man. By the way, check this free games that you can get on your PC or mobile. One of them is harry potter app game which is a great fantasy game for sure!

0
therouting avatar therouting 0 Точки

Account numbers are loads like a patron ID, or fingerprint, this is unique to every account holder. Similarly, routing numbers become aware of each banking group with a completely unique numerical ID. Routing and account numbers are assigned to indicate precisely where price range in a transaction are coming from and going to. Any time you're making an electronic price range transfer, as an example, both the routing and account numbers need to be provided to the relevant financial establishments.

click
click for info
click for more
click for more info

0
testss avatar testss 0 Точки

 

Acquire/Download or begin Streaming Décolonisations Season 1 in ITA Eng for nothing on the web Décolonisations full scene of TV arrangement downloadable for nothing from here. The ita-eng captions of Season 1 are remembered for the recordings. This TV arrangement has acquired fantastic appraisals from the Italian open. Download or stream total Décolonisations online 

https://reviewstrain.com
0
hakwinsmariya avatar hakwinsmariya 0 Точки

This implies you can watch the motion pictures on your telephone, iPad or PC. watch new movies However long there is a steady web association, watching films gets conceivable 24hours, seven days per week lasting through the year. How cool is that! The most significant thing watchers ought to be cautious about is infections. Get a dependable antivirus and visit infection free destinations.

0