-
March 23rd, 2009, 11:46 AM
#1
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.
-
March 23rd, 2009, 12:23 PM
#2
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..
-
March 23rd, 2009, 12:38 PM
#3
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'
-
March 23rd, 2009, 12:42 PM
#4
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 >>
-
March 23rd, 2009, 12:47 PM
#5
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?
-
March 23rd, 2009, 12:51 PM
#6
Re: Need help bad!!!
Anything inside quotes will be output as a string literal. Ditch the quotes and you should be okay.
-
March 23rd, 2009, 12:57 PM
#7
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..
-
March 23rd, 2009, 01:14 PM
#8
Re: Need help bad!!!
Originally Posted by stunnahayes
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.
-
March 23rd, 2009, 01:16 PM
#9
Re: Need help bad!!!
Originally Posted by stunnahayes
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.
-
March 23rd, 2009, 01:19 PM
#10
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.
-
March 23rd, 2009, 01:44 PM
#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?
-
March 23rd, 2009, 01:49 PM
#12
Re: Need help bad!!!
Describe what you'd do mathematically. The code will then look very similar.
-
March 23rd, 2009, 01:53 PM
#13
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.
-
March 23rd, 2009, 01:55 PM
#14
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 (% 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.
-
March 23rd, 2009, 02:07 PM
#15
Re: Need help bad!!!
ha ha im still stumped =( I understand what you mean with % i just have no clue how to write it...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|