HomeWork prompt

Hello! I am basically having trouble on a homework prompt and need a little help with scenarios that break my code. Basically the prompt is that there is a sled that can carry three items, fish, fur, and crafts, and the user is able to input the weight of the fish, fur, and crafts, and the carrying capacity of the sled. The goal of the program is to tell the user which combination or which of the three items they are able to carry to get as close as possible to the max value without going over. I am having a problem on the scenario where there are multiple doubles that work: for instance if the inputted value for each is 5, 5, and 5, and the max weight that the sled can carry is 10, the user can carry any combination of two of the goods. Here is my code so far, Thanks! :
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
int userFur = 0;
int userFish = 0;
int userCrafts = 0;
int userMax = 0;
int goodsTotal = 0;
int furFish = 0;
int furCrafts = 0;
int fishCrafts = 0;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

cout << "Please input your amount of fur: " << endl;
cin >> userFur;
cout << "Please input your amount of fish: " << endl;
cin >> userFish;
cout << "Please input your amount of crafts: " << endl;
cin >> userCrafts;
cout << "Please input a max weight: "<< endl;
cin >> userMax;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
goodsTotal = userFur + userFish + userCrafts;
furCrafts = userFur + userCrafts;
furFish = userFish + userFur;
fishCrafts = userFish + userCrafts;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (goodsTotal <= userMax) {
cout << "You can carry everything that you have!" << endl;
return 0;
}

if (furCrafts < userMax && furFish < userMax && fishCrafts < userMax){
if (furCrafts > furFish && furCrafts > fishCrafts) cout << "fur and crafts";
if (furFish > furCrafts && furFish > fishCrafts) cout << "fur and fish";
if (fishCrafts > furCrafts && fishCrafts > furFish) cout << "Fish and crafts";
return 0;
}

if (userFur < userMax && userFish < userMax && userCrafts < userMax) {
if (userFur > userFish && userFur > userCrafts) cout << "fur";
if (userFish > userFur && userFish > userCrafts) cout<< "Fish";
if (userCrafts > userFur && userCrafts > userFish) cout << "Crafts";
return 0;
}

if (userFur < userMax && userFish < userMax && userFur > userFish) cout << "Fur";
if (userFur < userMax && userFish < userMax && userFish > userFur) cout << "Fish";

if (userFish < userMax && userCrafts < userMax && userFish > userCrafts) cout << "Fish";
if (userFish < userMax && userCrafts < userMax && userCrafts > userFish) cout << "Fish";

if (userCrafts < userMax && userFur < userMax && userCrafts > userFur) cout << "Crafts";
if (userCrafts < userMax && userFur < userMax && userFur > userCrafts) cout << "Crafts";

}
Last edited on
Topic archived. No new replies allowed.