Author Topic: Noob Help PLZ  (Read 1371 times)

0 Members and 1 Guest are viewing this topic.

Offline chlortho

  • /dev/null
  • *
  • Posts: 11
  • Cookies: 1
    • View Profile
Noob Help PLZ
« on: 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.

Code: (cpp) [Select]
//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
« Last Edit: May 12, 2014, 07:51:41 am by Kulverstukas »
chlortho

Offline chlortho

  • /dev/null
  • *
  • Posts: 11
  • Cookies: 1
    • View Profile
Re: Noob Help PLZ
« Reply #1 on: May 12, 2014, 02:48:14 am »
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


« Last Edit: May 12, 2014, 02:50:23 am by chlortho »
chlortho

Offline daxda

  • Peasant
  • *
  • Posts: 114
  • Cookies: 112
  • Not the guy you're looking for
    • View Profile
    • Daxda on Github
Re: Noob Help PLZ
« Reply #2 on: May 12, 2014, 06:47:55 am »
Next time use code tags. Your int main is written as "in main", that could be a copy paster error though?
« Last Edit: May 12, 2014, 06:49:31 am by daxda »

Offline chlortho

  • /dev/null
  • *
  • Posts: 11
  • Cookies: 1
    • View Profile
Re: Noob Help PLZ
« Reply #3 on: May 12, 2014, 06:56:06 am »
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
« Last Edit: May 12, 2014, 06:58:09 am by chlortho »
chlortho

Offline daxda

  • Peasant
  • *
  • Posts: 114
  • Cookies: 112
  • Not the guy you're looking for
    • View Profile
    • Daxda on Github
Re: Noob Help PLZ
« Reply #4 on: May 12, 2014, 07:00:07 am »
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'.

Code: (cpp) [Select]
//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";
        }
    }


}
« Last Edit: May 12, 2014, 07:07:04 am by daxda »

Offline chlortho

  • /dev/null
  • *
  • Posts: 11
  • Cookies: 1
    • View Profile
Re: Noob Help PLZ
« Reply #5 on: May 12, 2014, 05:45:07 pm »
got it.  thanks for the help! 
chlortho

Offline ArkPhaze

  • Peasant
  • *
  • Posts: 136
  • Cookies: 20
  • null terminated
    • View Profile
Re: Noob Help PLZ
« Reply #6 on: June 12, 2014, 06:27:25 am »
How about some else if's and proper stream state flag checks? :)
sig=: ArkPhaze

[ J/ASM/.NET/C/C++ - Software Engineer ]