this is what the code does:
1. ask user for input (seeds color red or blue)
2. check the temp
for blue seed: if temp from 60-70, it grows to flower, else mushroom
for red seed: if temp is >= 75, it grows to flower,else mushroom
3. check for soil
for blue seed: if soil is try--->grows into sunflower
if soil is wet--->grows into dendelion
for red seed: the opposite from blue seed.
here is my code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string color="";
cout<<"what is the color of the seed? please either enter blue or red!: \n";
cin >> color;
int temp;
cout<<"what is the temperture? :\n";
cin >> temp;
string soil="";
cout<<"what kind of the soil? please either enter wet or dry! :\n";
cin >> soil;
if (color == "red")
{
if (temp >= 75)
{
if (soil=="wet")
{
cout <<"you get yourself a sunfolower :\n";
}
if (soil=="dry")
{
cout <<"you get yourself a dendelion :\n";
}
}
else
{
cout <<"Shit, you have a mushroom now! :\n";
}
}
if (color=="blue")
{
if (temp >= 60 || temp <= 70)
{
if (soil=="wet")
{
cout <<"you get yourself a dendelion :\n";
}
if(soil=="dry")
{
cout <<"you get yourself a sunfolower :\n";
}
else{
cout <<"Shit, you have a mushroom now! :\n";
}
}
}
}
when I run the code, it stops executing after asking the 3rd question, why? Help please.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string color="";
cout<<"what is the color of the seed? please either enter blue or red!: \n";
cin >> color;
int temp;
cout<<"what is the temperture? :\n";
cin >> temp;
string soil="";
cout<<"what kind of the soil? please either enter wet or dry! :\n";
cin >> soil;
if (color == "red")
{
if (temp >= 75)
{
if (soil=="wet")
{
cout <<"you get yourself a sunfolower :\n";
}
elseif (soil=="dry")
{
cout <<"you get yourself a dendelion :\n";
}
}
else
{
cout <<"Shit, you have a mushroom now! :\n";
}
}
elseif (color=="blue")
{
if (temp >= 60 && temp <= 70)
{
if (soil=="wet")
{
cout <<"you get yourself a dendelion :\n";
}
elseif(soil=="dry")
{
cout <<"you get yourself a sunfolower :\n";
}
}
else{
cout <<"Shit, you have a mushroom now! :\n";
}
}
return 0;
}
other than to speed things up, it's also for the else condition
for example
1 2 3 4 5 6 7 8 9
if( input == "yes"){
cout << "Accepted" << endl;
}
elseif( input == "no"){
cout << "Why not ?" << endl;
}
else {
cout << "You didn't answer the question in a way I can understand" << endl;
}
this is just a dumb example but try to get it
then please check if your condition is always true no matter what is the input
if( temp >= 60 || temp <= 70 ){
I take the example from your code
just try , whatever the temp is it's always true
so becareful
and also one more thing
use indentation ( space or tab ) to make your code easier to read for yourself at least
it's not hard to put the curly brace in the wrong place