It seems that you are encountering the conflicting types error. I may be mistaken, but I believethe error occurs because the CodeWars IDE assumes an existing main function while your original code defines the main function as int main().
#include <iostream> using namespace std; void myFunction() { int x = 1; int u = 0, g = 0, c = 0; cout << "quanti anni ha l'uomo? (alla donna non si chiede)" << endl; cin >> u; while (x <= u) { if (x == 1) { g = 15; c = 15; } if (x == 2) { g += 9; c += 9; } if (x >= 3) { g += 4; c += 5; } x++; } cout << "cane " << c << endl; cout << "gatto " << g; }
- #include <iostream>
- using namespace std;
int main(){- void myFunction() {
- int x = 1;
- int u = 0, g = 0, c = 0;
- cout << "quanti anni ha l'uomo? (alla donna non si chiede)" << endl;
- cin >> u;
while (x <= u){if (x == 1){- while (x <= u) {
- if (x == 1) {
- g = 15;
- c = 15;
- }
- if (x == 2) {
- g += 9;
- c += 9;
- }
- if (x >= 3) {
- g += 4;
- c += 5;
- }
- x++;
- }
- cout << "cane " << c << endl;
- cout << "gatto " << g;
return 0;}- }
// TODO: Replace examples and use TDD by writing your own tests Describe(PersonAgeCalculator) { It(should_calculate_dog_and_cat_ages_correctly) { // Test Case 1 { int u = 5; int expectedCaneAge = 39; int expectedGattoAge = 36; int x = 1; int c = 0, g = 0; while (x <= u) { if (x == 1) { g = 15; c = 15; } if (x == 2) { g += 9; c += 9; } if (x >= 3) { g += 4; c += 5; } x++; } Assert::That(c, Equals(expectedCaneAge)); Assert::That(g, Equals(expectedGattoAge)); } // Test Case 2 { int u = 1; int expectedCaneAge = 15; int expectedGattoAge = 15; int x = 1; int c = 0, g = 0; while (x <= u) { if (x == 1) { g = 15; c = 15; } if (x == 2) { g += 9; c += 9; } if (x >= 3) { g += 4; c += 5; } x++; } Assert::That(c, Equals(expectedCaneAge)); Assert::That(g, Equals(expectedGattoAge)); } // Test Case 3 { int u = 10; int expectedCaneAge = 64; int expectedGattoAge = 56; int x = 1; int c = 0, g = 0; while (x <= u) { if (x == 1) { g = 15; c = 15; } if (x == 2) { g += 9; c += 9; } if (x >= 3) { g += 4; c += 5; } x++; } Assert::That(c, Equals(expectedCaneAge)); Assert::That(g, Equals(expectedGattoAge)); } } };
- // TODO: Replace examples and use TDD by writing your own tests
Describe(any_group_name_you_want)- Describe(PersonAgeCalculator)
- {
It(should_do_something)- It(should_calculate_dog_and_cat_ages_correctly)
- {
Assert::That("some value", Equals("another value"));- // Test Case 1
- {
- int u = 5;
- int expectedCaneAge = 39;
- int expectedGattoAge = 36;
- int x = 1;
- int c = 0, g = 0;
- while (x <= u)
- {
- if (x == 1)
- {
- g = 15;
- c = 15;
- }
- if (x == 2)
- {
- g += 9;
- c += 9;
- }
- if (x >= 3)
- {
- g += 4;
- c += 5;
- }
- x++;
- }
- Assert::That(c, Equals(expectedCaneAge));
- Assert::That(g, Equals(expectedGattoAge));
- }
- // Test Case 2
- {
- int u = 1;
- int expectedCaneAge = 15;
- int expectedGattoAge = 15;
- int x = 1;
- int c = 0, g = 0;
- while (x <= u)
- {
- if (x == 1)
- {
- g = 15;
- c = 15;
- }
- if (x == 2)
- {
- g += 9;
- c += 9;
- }
- if (x >= 3)
- {
- g += 4;
- c += 5;
- }
- x++;
- }
- Assert::That(c, Equals(expectedCaneAge));
- Assert::That(g, Equals(expectedGattoAge));
- }
- // Test Case 3
- {
- int u = 10;
- int expectedCaneAge = 64;
- int expectedGattoAge = 56;
- int x = 1;
- int c = 0, g = 0;
- while (x <= u)
- {
- if (x == 1)
- {
- g = 15;
- c = 15;
- }
- if (x == 2)
- {
- g += 9;
- c += 9;
- }
- if (x >= 3)
- {
- g += 4;
- c += 5;
- }
- x++;
- }
- Assert::That(c, Equals(expectedCaneAge));
- Assert::That(g, Equals(expectedGattoAge));
- }
- }
- };