Hi, I'm trying to produce an algorithm with branching paths so that the output reads,in the context below, as follows:
Enter the seed color (red or blue):
red
Enter the temperature (F):
65
A mushroom will grow.
However, when I input the temperature at 65, it reads this instead:
Enter the seed color (red or blue):
red
Enter the temperature (F):
65
Enter the soil moisture (wet or dry):
I don't want it to ask me the soil moisture. I was trying to streamline the logic so that it wouldn't ask that redundant question, because if the seed is red and if the temperature is below 75, then it shouldn't ask that question. Can you please help me? The code is written below. Thank you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
//A red seed will grow into a flower when planted in soil
//temperatures above 75 degrees, otherwise it will grow into
//a mushroom. Assuming the temperature meets the conditions
//for growing a flower, planting the red seed in wet soil
//will produce a sunflower, and planting the red seed in dry
//soil will produce a dandelion.
//A blue seed will grow into a flower when planted in soil
//temperatures ranging from 60 to 70, otherwise it will grow
//into a mushroom. Assuming the temperature meets the conditions
//for growing a flower, planting the blue seed in wet soil will
//produce a dandelion and planting the blue seed in dry soil
//will produce a sunflower.
#include <iostream>
#include <string>
using namespace std;
int main()
{
//Get seed color
string seedColor = "";
cout << "Enter the seed color (red or blue): \n";
cin >> seedColor;
//Get temp
int temp = 0;
cout << "Enter the temperature (F): \n";
cin >> temp;
//if red seed
if(seedColor == "red")
{
// If temp >= 75
if(temp >= 75)
{
//Get the soil moisture
string soilMoisture = "";
cout << "Enter the soil moisture (wet or dry): \n";
cin >> soilMoisture;
//If the soil is wet
if(soilMoisture == "wet")
{
//Output sunflower
cout << "A sunflower will grow.\n";
}
//If the soil is dry
if(soilMoisture == "dry")
{
//Output dandelion
cout << "A dandelion will grow.\n";
}
}
//Otherwise
else
{
//Output mushroom
cout << "A mushroom will grow.\n";
}
}
//If blue seed
if (seedColor == "blue")
{
//If temp is between 60 and 70
if(temp >= 60 && temp <= 70)
{
//Get the soil moisture
string soilMoisture = "";
cout << "Enter the soil moisture (wet or dry): \n";
cin >> soilMoisture;
//If the soil is wet
if(soilMoisture == "wet")
{
//Output dandelion
cout << "A dandelion will grow.\n";
}
//If the soil is dry
if (soilMoisture == "dry")
{
//Output sunflower
cout << "A sunflower will grow.\n";
}
}
//Otherwise
else
{
//Output mushroom
cout << "A mushroom will grow.\n";
}
}
}
|