Thread: control flow question?

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    10

    control flow question?

    I have to make the following program: the user must input day and month, and the program to display which season is with words "winter" "spring" "summer" fall"

    What i do is

    Code:
    #include <iostream>
    #include <string>
    #include <cmath>
    using namespace std;
    
    int main()
    
    {
        int day, month;
        cin >> day >> "Please enter a date:\n";
        cin >> month >> "now enter a month:\n";
    
        switch (month)
        {
        case 1 : cout << "winter"; break;
        case 2 : cout << "winter"; break;
        case 3 : if (day<=19)
            {cout << "winter";
                    else << "spring"}; break;
        }
    
    
    return 0;
    
    }
    where i fail?is this a right approach?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    For one thing, you probably want to use cout to print those strings (e.g., "Please enter a date:\n") instead of trying to use cin to read into them.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    10
    Quote Originally Posted by laserlight View Post
    For one thing, you probably want to use cout to print those strings (e.g., "Please enter a date:\n") instead of trying to use cin to read into them.
    Thanks a lot, i've solved the problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  2. Exam Question - Possible Mistake?
    By Richie T in forum C++ Programming
    Replies: 15
    Last Post: 05-08-2006, 03:44 PM
  3. Updating a list control
    By MPSoutine in forum Windows Programming
    Replies: 2
    Last Post: 12-05-2003, 02:03 AM
  4. Lame question on dialog controls appearance
    By Templario in forum Windows Programming
    Replies: 2
    Last Post: 03-18-2003, 08:22 PM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM