EvilZone
Programming and Scripting => C - C++ => : chlortho May 12, 2014, 02:39:52 AM
-
I am just learning. This is a tutorial I got from the web. xcode isn't highlighting and defining what is exactly wrong (at least I don't think it is). Anyways.... can someone have a look and tell me what I have done wrong? Thanks, in advance. -chlortho
*.cpp also attached.
//Problem Statement
//A red seed will grow into a flower when planed 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 dandelion.
//
//A blue seed will gow 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.
//
//Write a program that will ask the ser to input the seed color, the soil temperature
//and whether the soil is wet or dry and then output what will grow.
#include <iostream>
#include <string>
using namespace std;
in 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;
// Get soil moisture
string soilMoisture = "";
cout << "Enter the soil moisture (wet or dry): \n";
cin >> soilMoisture;
// If red seed
if(seedColor == "red")
{
// If Temp >= 75
if(temp <= 75)
{
// 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 dendelion 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 is >= 60 && temp is <= 70)
{
// 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";
}
}
}
Staff note: use the code tags next time pl0x
-
i found that the O in the variable soilMoisture was capped so I fixed that.... it seems to not like the '>='
So frustrating.... this should be super simple...ugh
-
Next time use code tags. Your int main is written as "in main", that could be a copy paster error though?
-
Code tags?
I corrected the 'int' - thanks
This line is giving me the error: if(temp is >= 60 && temp is <= 70)
Invalid '>=' HTF else do you notate "greater than or equal to"?
Unknown type name 'temp' - I defined temp so this should be right. Right?
Expected ')' - no idea on this one
-
Read up on bbcode if you don't know the "code tags" term, it's used to display your code so we don't get eye cancer from staring at it too long.
Line 77, you don't use "is" inside an if check, that's a python thing only, remove it.
Line 88, you wrote soilMOisture instead of soilMoisture, replace capitalized 'O' with non caps 'o'.
//Problem Statement
//A red seed will grow into a flower when planed 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 dandelion.
//
//A blue seed will gow 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.
//
//Write a program that will ask the ser to input the seed color, the soil temperature
//and whether the soil is wet or dry and then output what will grow.
#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;
// Get soil moisture
string soilMoisture = "";
cout << "Enter the soil moisture (wet or dry): \n";
cin >> soilMoisture;
// If red seed
if(seedColor == "red")
{
// If Temp >= 75
if(temp <= 75)
{
// 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 dendelion 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)
{
// 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";
}
}
}
-
got it. thanks for the help!
-
How about some else if's and proper stream state flag checks? :)