C++ Homework using the "if" statement

Hello again:
I am having trouble declaring my variables. Can you please show me what I am doing wrong. The homework problem ask for me to use the "if" statement also, kinda having a few problems with that. Please see the question and my code below.

Thank you for your time.

Homework 3a:
Do using the if statement
Question:
Write, compile and run a C++ program named hw3a.cpp that reads in one integer that represents a total number of seconds and then breaks that number down to display the equivalent number of hours, minutes and seconds, all properly labeled.

Have your program ONLY do the calculation if the user enters a number LESS than 50,000 hours. If he enters 50,000 or more print an error message and quit.

Sample run:

Input a whole number of seconds less than 50,000:
7683
There are 2 hours, 8 minutes and 3 seconds in 7683 seconds

Sample run:

Input a whole number of seconds less than 50,000:
76099
Sorry, you were asked to enter a number less than 50,000

Source 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 Total Number of Seconds;
int Number of Minutes;
int Number of Hours;
int Number of Seconds;
int Y, X1, X2, X3, X4;
if (X1>Y):
cout << "What is the total number of seconds:\n";
cin >> totalnumSeconds;
cout << "What is the number of hours:\n";
cin >> numHours;
cout << "What is the number of minutes:\n";
cin >> numMinutes;
cout >> "What is the number of seconds:\n";
cin >> numSeconds;
if (X1>Y):
cout << "ERROR:" << endl;
return 0;
}

Closing thread as it is going off topic thanks to spoonlicker. You now have official warning about hijacking other people threads.
@Sundayy if you still need help with your work please create new thread and I'm sure people who been helping you and other who are willing to help will … Read More

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

This is a valid line: cout [B]<<[/B] "What is X1/60:\n"; This is the one with the error: cout [B]>>[/B] "What is (X3*360):\n"; What's different?
You've used the "stream extraction" 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.

>>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.

>>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.

Again, it's their choice. Code doesn't always have to be reused, you know? Not every one is going to be working for Microsoft, some people just do it for personal reasons and, in that case, the code can be memorized well or at least should be.

I just use unique names I come up with and when I pass by the names I automatically know what it'll do because "I" came up with it.

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.

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.

> 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.

> 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.

I don't work that way though.

I always begin and end or quit. I don't leave code sitting around for no reason, and if I'm done with it I'm done.

Either that or I'll lay off for a short-time but not long enough for me to forget what I've done. And what makes you think I'd wrote code and leave it there for no use? I'd either write it and use the program it produces or fail to complete it and delete it.

I am with using appropriate variable names.
They make debugging better, clearer program (and in this case, it's a homework!)
And, one should keep habit of this right from the beginning. Later, when you've developed, it'll be a bit difficult to adapt to the new style....

i totally agree with appropriate variable naming too. i far too often find myself stuck debugging only if i had just used better variable names the problem would be easier to isolate. It also helps other people read and understand your code when you ask for their help.

i totally agree with appropriate variable naming too. i far too often find myself stuck debugging only if i had just used better variable names the problem would be easier to isolate. It also helps other people read and understand your code when you ask for their help.

You could always put comments next to the variable news if you do have bad memory and forget what they would do or what they're for.