>Please give me any suggestions on the program.
>Product1, // declare indentifiers
>Product2, TotalSeconds;
Bad form. Ending a physical line with a comma so that you can use a single line comment and continue the logical line on the next physical line is poor style.
>Seconds = Usertime.substr(SecondC + 1, Usertime.size() - SecondC + 1;
Your parens don't match.
>int Hours = atoi(Hours.c_str());
>int Mins = atoi(Mins.c_str());
>int Secs = atoi(Secs.c_str());
atoi is declared in . Because you failed to include that header, calling atoi is wrong.
>cout << "There are " << cin TotalSeconds << " total seconds in the given time.";
cin should not be in this command at all.
>getch (); //Wrap-up and close
getch is a poor choice of function for this operation, but you also neglected to include getch's common header, .
I fail to see how the syntax errors would elude you since they cause the compiler to bitch and moan. What kind of suggestions were you hoping for with a broken program that fails to compile?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>i forgot to compile it before i posted it on here..
The compiler is one of your best tools for finding obvious problems. If you're too lazy to compile code before publishing it then you need to get your priorities straight.
>but i don't know how to correct them...
Then you lack the basic intelligence required to write programs, because I told you what was wrong and the solution can be gleaned from what I said. In order of my comments, excluding the one on style: Add a closing paren before the semicolon, include , remove cin, and include .
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Wow,
variables and types are a mess here! Narue is right, the compiler will bitch! Oops, where did the structure type come from?
Eric, doing this thing in small stages might help! Like your input section, comment out the other code, Compile and test each stage!
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
The problem is that you're trying to do too much, too soon. Clearly, the concept of data types is beyond you at this point, so trying to use std::strings and data type conversions will only frustrate you. I would recommend only using cin>> to read integers and cin.get() to throw away formatting characters from the stream, such as ':'. To read the user time you would do something like this:
// Read HH:MM:SS from standard input
cin>> Hours;
cin.get(); // Toss colon
cin>> Minutes;
cin.get(); // Toss colon
cin>> Seconds;
Once you become proficient with this simple method, you can move on to more concise methods. You also profit from the added benefit of having a stronger understanding of how the input stream works. This understanding can only come from working with streams at the character level.
>give me a break Narue..
Earn one and I'll give it to you.
>it's my first year in college, and my first attempt at Computer Science..
Is this supposed to be an excuse for your lack of common sense?
>and if I knew how to write programs like a pro I wouldn't be on here
I don't expect you to write programs like a pro. I do expect you to make more than a half-assed attempt though.
>what would you suggest that I do if I don't know how to correct an error in the compiler?
Research the error. Despite being intimidating, compiler warnings and errors are usually informative enough to point to a solution.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401