first you need make a variable where the user inputs the total of numbers
then you need to ask is the variable higher than 50 thousand if yes run your if statements to find hours mins and seconds, if not then display error message and exit
ninjatalon
Junior Poster in Training
81 posts since Feb 2011
Reputation Points: 11
Solved Threads: 3
Instead of naming your variables something doesn't make any sense, how about naming them something like totalseconds, hours, minutes, seconds.
Also, like one of the prior posters said, you have to calculate them WITHIN the program, not have the user enter the calculated value.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
Here is my second attempt, I am now getting on line 27, an error; no match for 'operator >>' in std::cout >> "What is (X3*360):\012"'.
Can you please tell me how to fix it, see my code below.
Thank You
CODE
//Variables:
//X1 = Total Number of Seconds
//X2 = Number of Minutes = X1/60
//X3 = Number of Hours = X1/360
//X4 = Number of Seconds = X3*360
//Y = 50000
#include <iostream>
using namespace std;
int main()
{
int X1,X2,X3,X4;
int Y=50000;
if (X1>Y);
cout << "What is X1:\n";
cin >> X1;
cout << "What is X1/360:\n";
cin >> X3;
cout << "What is X1/60:\n";
cin >> X2;
cout >> "What is (X3*360):\n";
cin >> X4;
if (X1>Y);
cout << "ERROR:" << endl;
return 0;
}
This is a valid line: cout <strong><<</strong> "What is X1/60:\n";
This is the one with the error: cout <strong>>></strong> "What is (X3*360):\n";
What's different?
You've used the "streamextraction" operator (operator>>) which is an input operator on an output stream. Output streams don't have input operators. You need to use the "stream injection" operator (operator<<) on an output stream.
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
>>The point of being a programmer is to name a variable any thing the programmer wants, not to hear how their named variables are wrong.
To a reasonable extent, yes. The problem is, if you use a meaningless name, it makes it very difficult to know what the value in the variable is supposed to represent.
If you have a program that calculates the Pythagorean Theorem, the variable names "side1Length", "side2Length", and "hypotenuseLength" are more meaningful than 'x', 'y', and 'z'. If you go back to your program later, let's say a year from now, will you be able to easily tell what 'x', 'y' and 'z' represent? Probably not, you'll either have to hope that the author provided useful comments or you'll have to track them down through the code and see how they're used to figure it out.
This is part of a concept commonly called "self-documenting code". The idea is to make your code as readable as possible. Ideally, your code is so easily readable that many comments can be eliminated as redundant.
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
I automatically know what it'll do because "I" came up with it.
Until you leave the code and come back in a year and it looks like it was written by someone else. Then you're SOL.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
You have been using the executable, and the program has been working, but you've recently found a bug that you want to fix. You get back to your code to fix it and you now have no idea what variable/function you're looking for because none of the names make sense. As a result, you have to completely reverse-engineer the software to figure out what section of code to look at instead of just going to the appropriate function and making the required change.
I think at this point it would be a good idea to start a new thread if you want to discuss the validity/value of good variable names further.
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
And give me any one reason, big or small, as to why I'd leave code sitting for one year and not use it, delete it or work around with it?
You might write yourself a tool and use it but not need to examine the code. But then a subtle bug finally surfaces one day or you might want to add a feature. If all you write are throwaway programs then be as sloppy as you want. But if your programs are meant to last, then the code should be written to last as well.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
> And give me any one reason, big or small, as to why I'd leave code sitting for one year and not use it, delete it or work around with it?
Any working programmer is going to have plenty of code around that they haven't looked at in over a year. I have production code that I probably haven't looked at in over five years.
I can absolutely guarantee you'll understand why meaningful variable names are not just a trivial nitpick suggestion if you have to work on some code you wrote years ago.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
Even if you don't have long-term code as a consideration, using clear and meaningful variable names is useful in maintaining focus and understanding of what any section of code is doing.
As already explained above, using a name like "hours" instead of "X3" makes the logic a lot easier to follow - even for the person writing it.
And let's give this thread back to the OP now. We've interjected more than enough on variable naming.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
To OP you are making an if statement if x1 is greater than y
But you x1 doesn't have a value yet.
You should ask the user what x1 is first and then compare if x1 is greater than y
ninjatalon
Junior Poster in Training
81 posts since Feb 2011
Reputation Points: 11
Solved Threads: 3