Building C++ programs

This is a discussion on Building C++ programs within the C++ Programming forums, part of the General Programming Boards category; I'm taking a computer science class and I have to write 3 programs in C++. My problem is I don't ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    1

    Building C++ programs

    I'm taking a computer science class and I have to write 3 programs in C++. My problem is I don't know how to get started when trying to solve these 3 problems. Is there anyone there that can help. Once I know who can help I'll let you know what the 3 programs I have to write are.

    the problems i have are how to calculate the number of days between two dates including leap year, writing a program for the game Nim where computer plays against human opponent, and the other one is calculating the sum of every other digit with a long number given

    this is what ive done so far but the program isnt working
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    using namespace std;
    int getDays(int month);
    int getInteger;

    void main ()

    {
    int MonthDays; // equal to the total number of days from the past months combined.
    int Day; // used to enter a specific day of the month (i.e. the 22nd or 3rd)
    int Choice; // Used to select from the switch statement
    int Date1, Date2;

    //Displays the months user will choose from and input
    cout << "1." << " January ";
    cout << "\t\t2." << setw (4) << " February" << endl;
    cout << "3." << " March ";
    cout << "\t\t4." << setw (4) << " April " << endl;
    cout << "5." << " May ";
    cout << "\t\t\t6." << setw (4) << " June " << endl;
    cout << "7." << " July " ;
    cout << "\t\t8." << setw (4) << " August " << endl;
    cout << "9." << " September " ;
    cout << "\t\t10." << setw (4) << " October " << endl;
    cout << "11." << " November " ;
    cout << "\t\t12." << setw (4) << " December " << endl;


    cout << "\nEnter the month of the first date: ";
    Choice = getInteger();
    MonthDays = getDays(Choice);

    cout << "Enter the day of the month: ";
    Day = getInteger();
    Date1 = MonthDays + Day;
    cout << "Days: " << Date1 << "\n\n"; // Displays the total number of days for date1
    // Stops Retrieving the info for the first date

    // Retrieving the info for the second date starts here

    cout << "Enter the month for the second date: ";
    Choice = getInteger;

    MonthDays = getDays(Choice);

    cout << "Enter the day of the month: ";
    Day = getInteger;

    Date2 = MonthDays + Day;
    cout << "Days: " << Date2 << "\n\n";

    cout << "The number of days between the two dates is: " << abs(Date1 - Date2) << endl;
    }

    int getDays(int month){
    int sum = 0;
    int days = 0;
    for (int cnt = 1; cnt < month; cnt++){
    switch(cnt){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
    days = 31;
    break;
    case 2:
    days = 28;
    break;
    case 4:
    case 6:
    case 9:
    case 11:
    days = 30;
    break;
    }
    sum += days;
    }
    return sum;
    }
    Last edited by lex254; 03-31-2010 at 07:38 PM.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Edit your post, use [code][/code] tags around your code. It makes your code much more readable.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    Once I know who can help I'll let you know what the 3 programs I have to write are.
    it works the other way around amigo

    edit >

    o i see you have already corrected that..? anyway what is not working? it might be better to post the relevant part you think is wrong, after you fixed the indenting...
    Last edited by rogster001; 04-01-2010 at 07:08 AM. Reason: apology

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-25-2010, 02:54 AM
  2. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 06:32 AM
  3. building stand-alone programs...is there an easy way?
    By tenken in forum C++ Programming
    Replies: 2
    Last Post: 12-21-2006, 09:12 PM
  4. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 04:42 AM
  5. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 03:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21