>How do I get the highlighted lines below to center above the ****************
Print a bunch of spaces before Hours:
cout<<" "<< Hours <<":"<< Mins <<":"<< Secs <<endl;
>And why won't the program give me the total seconds after I entered the formula
Amazing. Getting a decent question out of you people is like pulling teeth. Read very carefully: What is it doing? What were you expecting it to do? How does the first answer differ from the second?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>still doesn't give me total seconds
I'm not playing this game. Answer my questions and I'll help you; otherwise you can just sit and wait until someone less capable thinks he knows what the answer is.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Thank you, now was that so hard? The problem is that you're trying to parse an empty string. Time has the default contents (""), so your finds and substr's don't do very much. As a result, your atoi calls also don't do too much. Just be happy you aren't doing any divisions. ;)
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
I tried to do something similar but much more simple, but i dont know what i did wrong. Wont compile it right.
//Clock for seconds
#include <iostream.h>
int main ()
{
int HH;
int MM;
int SS;
int result;
cout << "Enter Hours :HH:";
cout << " ";
cin >> HH;
cout << "Enter Minutes :MM:";
cout << " ";
cin >> MM;
cout << "Enter Seconds :SS:";
cout << " ";
cin >> SS;
cout << HH ":" MM ":" SS;
cout " ";
cout "*****************";
result = HH * 60 + MM * 60 + SS;
cout << result;
cin.get ();
return 0;
}
Don't know if i even did anyhting right, im just learning and havn't even finished the Tutorial, and am on like 1.4 of it, and tried to do it,dont know much about C++ yet...
N3wbi3C0d3r
Junior Poster in Training
67 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
I tried to do something similar but much more simple, but i dont know what i did wrong. Wont compile it right.
//Clock for seconds
#include <iostream.h>
int main ()
{
int HH;
int MM;
int SS;
int result;
cout << "Enter Hours :HH:";
cout << " ";
cin >> HH;
cout << "Enter Minutes :MM:";
cout << " ";
cin >> MM;
cout << "Enter Seconds :SS:";
cout << " ";
cin >> SS;
cout << HH ":" MM ":" SS;
cout " ";
cout "*****************";
result = HH * 60 + MM * 60 + SS;
cout << result;
cin.get ();
return 0;
}
Don't know if i even did anyhting right, im just learning and havn't even finished the Tutorial, and am on like 1.4 of it, and tried to do it,dont know much about C++ yet...
There are a couple of << missing and hour has 60*60 seconds.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
Thx;) just looked over it on the site, ill try what i can and try to get it to work
N3wbi3C0d3r
Junior Poster in Training
67 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
//Clock for seconds
#include <iostream.h>
int main () {
int HH;
int MM;
int SS;
int result;
cout << "Enter Hours :HH:";
cout << " "<<endl;
cin >> HH;
cout << "Enter Minutes :MM:";
cout << " " endl;
cin >> MM;
cout << "Enter Seconds :SS:";
cout << " " endl;
cin >> SS;
cout << HH << ":" << MM << ":" << SS; cout " " endl;
cout " " endl;
cout "*****************";
result = ((HH * 60) + MM * 60) + SS;
cout << result;
cin.get ();
return 0;
}
Well, thisis whats updated, and the errors it gives me are as fallow:
2 C:\Dev-Cpp\include\c++\3.3.1\backward\iostream.h:31, from C:\Dev-Cpp\Time.cpp In file included from C:/Dev-Cpp/include/c++/3.3.1/backward/iostream.h:31, from C:/Dev-Cpp/Time.cpp
2 C:\Dev-Cpp\Time.cpp from C:/Dev-Cpp/Time.cpp
2 C:\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated.
C:\Dev-Cpp\Time.cpp In function `int main()':
13 C:\Dev-Cpp\Time.cpp syntax error before `;' token
16 C:\Dev-Cpp\Time.cpp syntax error before `;' token
18 C:\Dev-Cpp\Time.cpp syntax error before string constant
Any ideas whats wrong now???
N3wbi3C0d3r
Junior Poster in Training
67 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
You're missing a few << operators in your output statements.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
//Clock for seconds
#include <iostream.h>
int main ()
{
int HH;
int MM;
int SS;
int result;
cout << "Enter Hours HH: ";
cout << " ";
cin >> HH;
cout << "Enter Minutes MM: ";
cout << " ";
cin >> MM;
cout << "Enter Seconds SS:";
cout << " ";
cin >> SS;
cout << HH << ":" << MM << ":" << SS;
cout << " ";
cout << "*****************" << endl;
result = ((HH * 60) + MM * 60) + SS;
cout << result;
cin.get ();
return 0;
}
Alright fixed it up, it compiles, and runs, but i get to the point were it hits:
Enter Hours HH: 06
Enter Minutes MM: 30
Enter Seconds SS: 59
After the seconds, i press enter, and it closes the file. Any ideas on what i did wrong?
N3wbi3C0d3r
Junior Poster in Training
67 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
>Any ideas on what i did wrong?
Yes, your use of cin's >> operator left a newline in the stream for cin.get() to read immediately. The desired effect of pausing until you had a chance to read the output and type enter never happened. This is a typical problem when the naive cin.get() solution is used for keeping a window open and the program grows enough to introduce >>'s issues.
There are several ways of fixing the problem, but most of them are what you would consider obscure. The simplest solution is a loop:
//Clock for seconds
#include <iostream.h>
int main ()
{
int HH;
int MM;
int SS;
int result;
cout << "Enter Hours HH: ";
cout << " ";
cin >> HH;
cout << "Enter Minutes MM: ";
cout << " ";
cin >> MM;
cout << "Enter Seconds SS:";
cout << " ";
cin >> SS;
cout << HH << ":" << MM << ":" << SS;
cout << " ";
cout << "*****************" << endl;
result = ((HH * 60) + MM * 60) + SS;
cout << result;
while ( cin.get() != '\n' )
;
cin.get ();
return 0;
}
This loop clears the input stream so that the next call to cin.get() will be forced to wait for input.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Thankyou very much, the tutorial showed me how to do that, but i just spaced that thats something i should do...heh
N3wbi3C0d3r
Junior Poster in Training
67 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0