我不是在編程太goood,其實我已經開始和給自己一門功課,隨意說我是個菜鳥。程序拒絕進入第二個語句
這裏的問題陳述:
你可以種兩號種子之一(藍色或紅色) 種植在土壤溫度高於75度時,阿紅將長成一朵花,否則,它會成長爲一個蘑菇假設溫度滿足種植花卉的限制,溼土壤中的紅色種子會產生向日葵,在乾燥的土壤中種植紅色種子會產生d子。 藍色的種子在土壤溫度下會產生花朵。從60-70 F度。或者它的蘑菇。在潮溼的土壤的幹
這裏蒲公英的代碼:
*
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
string plantedSeed = "";
string seedColor = "";
cout << "What color will the seed be? (red/blue): \n";
getline(cin, seedColor);
int soilTemperature = 0;
cout << "What temperature will the soil have?\n";
cin >> soilTemperature;
if (seedColor == "red")
{
if (soilTemperature >= 75)
plantedSeed = "mushroom";
if (soilTemperature < 75)
{
string seedState = "";
cout << "Enter the state of the soil in which the seed is plantet to (wet/dry)\n";
getline(cin, seedState);
if (seedState == "wet")
plantedSeed = "sunflower";
if (seedState == "dry")
plantedSeed = "dandelion";
}
}
if(seedColor == "blue")
{
if (soilTemperature >= 60 && soilTemperature <= 70)
plantedSeed = "mushroom";
else
{
string seedState = "";
cout << "Enter the state of the soil in which the seed is plantet to (wet/dry)\n";
getline(cin, seedState);
if (seedState == "wet")
plantedSeed = "dandelion";
if (seedState == "dry")
plantedSeed = "sunflower";
}
}
cout << "The planted seed has transformed into: " << endl;
cout << plantedSeed << endl;
system("pause");
return 0;
}
* 的問題是程序拒絕進入,如果(soilTemperature < 75)語句
if (seedColor == "red")
{
if (soilTemperature >= 75)
plantedSeed = "mushroom";
if (soilTemperature < 75)
{
string seedState = "";
cout << "Enter the state of the soil in which the seed is plantet to (wet/dry)\n";
getline(cin, seedState);
if (seedState == "wet")
plantedSeed = "sunflower";
if (seedState == "dry")
plantedSeed = "dandelion";
}
}
它是藍色的一樣。
使用字符串比較功能。 –