CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Mar 2009
    Posts
    11

    Need help bad!!!

    Yes I am a college student needing help on a project.

    I need to write a program which takes as input from the keyborad two different lengths of time.

    1) adds them together and prints the result out in the most efficent form
    2) subtracts the second from the first and prints the result in the most efficent form.

    The first time period will always be bigger then than the 2nd
    there is 365 days in a year no using leap year.
    The user will always enter the data in correctly

    for a example (output) looks like this

    First time period = 4 years, 40 weeks and 5 days
    second time period = 2 years 26 weeks and 6 days

    addition resultant = 7 years 15 weeks and 4 days
    subtraction resultant = 2 years 13 weeks and 6 days

    WE cant not use if statements..
    file name is addandsubtime.cpp.
    output must be centered

    someone please help me I need help bad.. I am so lost in this program. IF someone could right up a program or walk me though what I need to do please get a hold of me asap aim is stunnahayes44 or get back at me on year ty so much.

  2. #2
    Join Date
    Mar 2009
    Posts
    11

    Re: Need help bad!!!

    well I am knew to this site.. but for my project this is what I have so far..
    # include <iostream>
    # include <string>
    # include <iomanip>
    # include <cmath>

    using namespace std;
    const int DAYS_IN_WEEK = 7;
    const int WEEKS_IN_YR = 52;
    const int DAYS_IN_YR = 365;

    int main(void)
    {

    int days;
    int weeks;
    int Years;
    int week1;
    int week2;

    int adddays1;
    int addweeks1;
    int addyears1;

    int adddays2;
    int addweeks2;
    int addyears2;

    int subdays1;
    int subweeks1;
    int subyears1;

    int subdays2;
    int subweeks2;
    int subyears2;


    cout << fixed << showpoint;

    cin >> years1 weeks1 days1 >> endl;
    cin >> years2 weeks2 days2 >> endl;



    cout >> "addition resultant = (year1 + year2) + (week1 + week2) + (day1 + day2)" >> endl;

    return 0;

    }

    I have errors in it but I think I am on the right track but can someone help me please get the bugs out..

  3. #3
    Join Date
    Mar 2009
    Posts
    11

    Re: Need help bad!!!

    now what I have..

    # include <iostream>
    # include <string>
    # include <iomanip>
    # include <cmath>

    using namespace std;
    const int DAYS_IN_WEEK = 7;
    const int WEEKS_IN_YR = 52;
    const int DAYS_IN_YR = 365;

    int main()
    {

    int days1;
    int weeks1;
    int years1;
    int years2;
    int weeks2;
    int days2;



    int adddays1;
    int addweeks1;
    int addyears1;

    int adddays2;
    int addweeks2;
    int addyears2;

    int subdays1;
    int subweeks1;
    int subyears1;

    int subdays2;
    int subweeks2;
    int subyears2;


    cout << fixed << showpoint;

    cin >> years1, weeks1, days1;
    cin >> years2, weeks2, days2;



    cout >> (addyears1 + addyears2) + (addweeks1 + addweeks2) + (adddays1 + adddays2) >> endl;

    return 0;

    }

    but I am getting this error:
    1>s:\cis143\assignment 2\assignment 2\addandsubtime.cpp(51) : error C2784: 'std::basic_istream<_Elem,_Traits> &std:perator >>(std::basic_istream<_Elem,_Traits> &,const std::_Smanip<_Arg> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std:stream'

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Need help bad!!!

    You seem to be doing fine on your own.

    However, you may want to look at your cout statement. You need << not >>

  5. #5
    Join Date
    Mar 2009
    Posts
    11

    Re: Need help bad!!!

    ok I did.. have


    # include <iostream>
    # include <string>
    # include <iomanip>
    # include <cmath>

    using namespace std;
    const int DAYS_IN_WEEK = 7;
    const int WEEKS_IN_YR = 52;
    const int DAYS_IN_YR = 365;

    int main()
    {

    int days1;
    int weeks1;
    int years1;
    int years2;
    int weeks2;
    int days2;



    int adddays1;
    int addweeks1;
    int addyears1;

    int adddays2;
    int addweeks2;
    int addyears2;

    int subdays1;
    int subweeks1;
    int subyears1;

    int subdays2;
    int subweeks2;
    int subyears2;


    cout << fixed << showpoint;

    cin >> years1, weeks1, days1;
    cin >> years2, weeks2, days2;



    cout << "years1 + years2 + weeks1 + weeks2 + days1 + days2" << endl;

    return 0;

    }

    but I get this output

    2 20 2
    years1 + years2 + weeks1 + weeks2 + days1 + days2
    Press any key to continue . . .

    its not letting me input 2 decades
    and I need it to add the first year and the 2nd year together but first i need to make to let me input 2 decades.. anyone have suggestions on what I should do?

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Need help bad!!!

    Anything inside quotes will be output as a string literal. Ditch the quotes and you should be okay.

  7. #7
    Join Date
    Mar 2009
    Posts
    11

    Re: Need help bad!!!

    yeah I did that now I get a DEBUG ERROR =(
    saying run-time check Failure #3 the variable ' week1' is being used without being defined..

  8. #8
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Need help bad!!!

    Quote Originally Posted by stunnahayes View Post
    yeah I did that now I get a DEBUG ERROR =(
    saying run-time check Failure #3 the variable ' week1' is being used without being defined..
    You are using weeks, not week.

    btw... I assume you mean you get a compile error, not a runtime error... because your program won't compile when you use non-existing variables.

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Need help bad!!!

    Quote Originally Posted by stunnahayes View Post
    yeah I did that now I get a DEBUG ERROR =(
    saying run-time check Failure #3 the variable ' week1' is being used without being defined..
    And it's correct. Look closely at what it's telling you.

  10. #10
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Need help bad!!!

    There's an improper use of the comma operator in your cin statements.

    In general: Don't use commas unless you really have a good reason. They don't do what you think they do.

  11. #11
    Join Date
    Mar 2009
    Posts
    11

    Re: Need help bad!!!

    ok ty for your help so far I have a little problem now that I know it deal with the code. ok I run and when I use numbers that should add up but not go past 7 days I get this.

    2
    27
    5
    1
    11
    4
    addition resultant = 3 years, 38 weeks and 9 days
    subtraction resultant = 1 years, 16 weeks and 1 days
    Press any key to continue . . .

    my code:
    # include <iostream>
    # include <string>
    # include <iomanip>
    # include <cmath>

    using namespace std;
    const int DAYS_IN_WEEK = 7;
    const int WEEKS_IN_YR = 52;
    const int DAYS_IN_YR = 365;

    int main()
    {

    int years1;
    int weeks1;
    int days1;

    int years2;
    int weeks2;
    int days2;




    cout << fixed << showpoint;

    cin >> years1;
    cin >> weeks1 ;
    cin >> days1;


    cin >> years2 ;
    cin >> weeks2;
    cin >> days2;



    cout << "addition resultant = " << years1 + years2 << " " << "years" << "," << " "
    << weeks1 + weeks2 << " " << "weeks" << " "<<"and "
    << days1 + days2 << " " << "days" << endl;

    cout << "subtraction resultant = " << years1 - years2 << " " << "years" << "," << " "
    << weeks1 - weeks2 << " " << "weeks" << " " <<"and "
    << days1 - days2 << " " << "days" << endl;

    return 0;

    }

    how do I get the days to role over 2 weeks when it goes over to 7 days and etc for weeks into years?

  12. #12
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Need help bad!!!

    Describe what you'd do mathematically. The code will then look very similar.

  13. #13
    Join Date
    Mar 2009
    Posts
    11

    Re: Need help bad!!!

    yeah IDk how to do it without if statements.. and would it go in my cout statement or in a line by itself? more details please it would help.

  14. #14
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Need help bad!!!

    Ah, no if statements, didn't see that requirement.

    Okay, here's a hint: Integer division disregards remainders, while the modulus operator (&#37 gives you only the remainder.

    You'd definitely put this on a separate line. I'm sure you *could* put it in the output statement, but that would needlessly confuse things.

  15. #15
    Join Date
    Mar 2009
    Posts
    11

    Re: Need help bad!!!

    ha ha im still stumped =( I understand what you mean with &#37; i just have no clue how to write it...

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured