Ошибки из-за невнимательности.
Первое, нам нужен здесь только iostream
Второе, второй include меняем на подключение пространства имен (namespace std)
Ну и косяк со скобками, исправленный код ниже:
#include <iostream>
using namespace std;
int main()
{
int x;
cout << "Input city: ";
cin >> x;
switch (x)
case 1: cout << "1-150";
break;
case 2: cout << "2-250";
case 3: cout << "3-300";
case 4: cout << "4-180";
case 5: cout << "5-230";
case 6: cout << "6-290";
case 7: cout << "7-165";
default: cout << "Error";
}
return 0;
unsigned perfectSquareLessOrEqual(unsigned n) {
unsigned sum = 0;
for (unsigned i = 1; (sum + i) <= n; i += 2)
sum += i;
return sum;
int main() {
unsigned x, y;
std::cin >> x >> y;
const unsigned a = perfectSquareLessOrEqual(x) + perfectSquareLessOrEqual(y);
const unsigned b = perfectSquareLessOrEqual(x + y);
if (a < b)
std::cout << "Petya gives paint to Vasya";
else if (a > b)
std::cout << "Petya leaves paint to himself";
else
std::cout << "Equal";
Объяснение:
Ошибки из-за невнимательности.
Первое, нам нужен здесь только iostream
Второе, второй include меняем на подключение пространства имен (namespace std)
Ну и косяк со скобками, исправленный код ниже:
#include <iostream>
using namespace std;
int main()
{
int x;
cout << "Input city: ";
cin >> x;
switch (x)
{
case 1: cout << "1-150";
break;
case 2: cout << "2-250";
break;
case 3: cout << "3-300";
break;
case 4: cout << "4-180";
break;
case 5: cout << "5-230";
break;
case 6: cout << "6-290";
break;
case 7: cout << "7-165";
default: cout << "Error";
break;
}
return 0;
}
#include <iostream>
unsigned perfectSquareLessOrEqual(unsigned n) {
unsigned sum = 0;
for (unsigned i = 1; (sum + i) <= n; i += 2)
sum += i;
return sum;
}
int main() {
unsigned x, y;
std::cin >> x >> y;
const unsigned a = perfectSquareLessOrEqual(x) + perfectSquareLessOrEqual(y);
const unsigned b = perfectSquareLessOrEqual(x + y);
if (a < b)
std::cout << "Petya gives paint to Vasya";
else if (a > b)
std::cout << "Petya leaves paint to himself";
else
std::cout << "Equal";
return 0;
}
Объяснение: