Vehicle Purchase on cpp

im having a problem i cant solve with the second parameter of the activity. I did anything i could, but it stills says all the test from 6 to 10 have failed.

std::string choose_vehicle(std::string option1, std::string option2) {
    if (option1.substr(option1.find (' ') + 1) < option2.substr(option2.find (' ') + 1)){
        return "you should choose" + option1;
    } else  {
        return "you should choose" + option2;
    }

this is what i did. if someone can help me out i would apreciate that.

Could you share a failed test (using a codeblock and not a screenshot)?

FAILED:
  REQUIRE( vehicle_purchase::choose_vehicle(choice1, choice2) == "Bugatti Veyron is clearly the better choice." )
with expansion:
  "you should chooseFord Pinto"
==
"Bugatti Veyron is clearly the better choice."
at /tmp/vehicle-purchase/vehicle_purchase_test.cpp:36
FAILED:
  REQUIRE( vehicle_purchase::choose_vehicle(choice1, choice2) == "Chery EQ is clearly the better choice." )
with expansion:
  "you should chooseChery EQ"
==
"Chery EQ is clearly the better choice."
at /tmp/vehicle-purchase/vehicle_purchase_test.cpp:42```
FAILED:
  REQUIRE( vehicle_purchase::choose_vehicle(choice1, choice2) == "Ford Focus is clearly the better choice." )
with expansion:
  "you should chooseFord Focus"
==
"Ford Focus is clearly the better choice."
at /tmp/vehicle-purchase/vehicle_purchase_test.cpp:48
```
```
FAILED:
  REQUIRE( vehicle_purchase::choose_vehicle(choice1, choice2) == "2018 Bergamont City is clearly the better choice." )
with expansion:
  "you should choose2018 Bergamont City"
==
"2018 Bergamont City is clearly the better choice."
at /tmp/vehicle-purchase/vehicle_purchase_test.cpp:54
```
```
FAILED:
  REQUIRE( vehicle_purchase::choose_vehicle(choice1, choice2) == "Bugatti Veyron is clearly the better choice." )
with expansion:
  "you should chooseBugatti Veyron"
==
"Bugatti Veyron is clearly the better choice."
at /tmp/vehicle-purchase/vehicle_purchase_test.cpp:60
```

these are all the error they give

Let’s look at one specific test.

Do you understand what this test is checking?

yes i do, but i dont know why

You don’t know why what? Why your code returns you should chooseFord Pinto? Why the test expects Bugatti Veyron is clearly the better choice.?

no, neither of them. I know the program should return the ford Pinto because the letter “p” is before the “V”. The thing here is that i dont know why is my code not doing well.

B comes before F. The correct return value is Bugatti Veyron is clearly the better choice.

The instructions say,

The returned string should follow the pattern of “<CHOSEN_VEHICLE> is clearly the better choice.”

oh yeah i know that, but the excersice takes the first letter of the model of the car, not the brand, thats my problem there.

1 Like

Where do you see that? That’s not what the test output suggests.

The oytpyt suggest says for example that buggati veyron > ford Pinto, so i should choose the ford pinto. And the obly way for that to happen is yo use the first letter of the model, not the brand of the car. Thats what i think.
I know i must probably be wrong but idk.

The output says you should pick buggati veyron over the ford Pinto. That’s because b comes before v and you’re supposed to use the string (car make) which comes first in the alphabet. It is not looking at the model.

How would you do it?

if (option1 < option2) { // use option1

hi, i found the error on my code, the thing was that i wasn’t typing " is clearly the better choice." after typing the choice, and that was obligatory necessary, thanks for helping!!!