473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

conversion of time in seconds using structure

i create a structure called time. Its three members, all type int called hours, minutes, and seconds. This is in 12:59:59 format and i finally want to print out the total number of seconds represented by this time value.
long totalsecs = t1.hours*3600 + t1.minutes*60 + t1.seconds
i am using this formula but facing errors can any one solve it??
Sep 25 '13 #1

✓ answered by Nepomuk

Hi haniya ali and welcome to bytes.com!

At first glance the formular looks ok, so you'll have to be a little more specific: What errors are you facing? What goes wrong and what are you expecting?

4 4492
Nepomuk
3,112 Expert 2GB
Hi haniya ali and welcome to bytes.com!

At first glance the formular looks ok, so you'll have to be a little more specific: What errors are you facing? What goes wrong and what are you expecting?
Sep 25 '13 #2
Expand|Select|Wrap|Line Numbers
  1. struct TIME
  2.     { 
  3.     int seconds; 
  4.     int minutes;
  5.     int hours; 
  6.      };
  7.     void totalsecs(struct TIME t1,struct TIME*totalsecs ); 
  8. using namespace std;
  9.  
  10. int main()
  11. {     
  12.     struct TIME t1,totalsecs,hours,minutes,; 
  13.     cout<<"Enter the time: \n";
  14.     cout<<"Enter hours, minutes and seconds respectively: "; 
  15.     cin>>t1.hours>>t1.minutes>>t1.seconds;
  16.     cout<<t1.hours<<":"<<t1.minutes<<":"<<t1.seconds;
here is the whole code it works properly but when i apply the formula to calclute seconds then give error
Sep 26 '13 #3
Nepomuk
3,112 Expert 2GB
You're declaring totalsecs as a struct TIME in line 12 and in your formular as a long. Such double declarations are not allowed in C/C++; here's a version that works:
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2.  
  3. struct TIME
  4.     { 
  5.     int seconds; 
  6.     int minutes;
  7.     int hours; 
  8.      };
  9.     void totalsecs(struct TIME t1,struct TIME*totalsecs ); 
  10. using namespace std;
  11.  
  12. int main()
  13. {     
  14.     struct TIME t1; // totalsecs and others probably aren't of type "TIME", are they?
  15.     cout<<"Enter the time: \n";
  16.     cout<<"Enter hours, minutes and seconds respectively: "; 
  17.     cin>>t1.hours>>t1.minutes>>t1.seconds;
  18.     cout<<t1.hours<<":"<<t1.minutes<<":"<<t1.seconds<<endl;
  19.     long totalsecs = t1.hours*3600 + t1.minutes*60 + t1.seconds;
  20.     cout<<"That makes "<<totalsecs<<" seconds"<<endl;
  21.  
  22.     return 0;
  23. }
  24.  
Sep 26 '13 #4
thank you i really works now.
Sep 26 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Valiz | last post by:
Hi, I am updating system time with IRIG time source which sends irregular pulses as shown below 11000011111100111111111111111111....(1-IRIG present and 0-IRIG not present) I need to update...
1
by: PCHOME | last post by:
Hi! I am new to C. If I want to know the CPU time needed to run a sequence of my C code(not necessary the whole program, maybe just part of my program), What function should I use? Some...
0
by: Pravin | last post by:
I have following architecture. c# code --> managed c++ code (wrapper) -> c wrapper code to third party tool --> third party tool written in c. c# code sends some data and a delegate to c++...
4
by: Chuck Ritzke | last post by:
Okay, just when I thought I was starting to understand stuff. In VB6... Type MyDataType Dim Value1 as double Dim Value2 as double End Type Dim MyData1 as MyDataType Dim MyData2 as MyDataType
1
by: Chris | last post by:
I have an ASP.NET v1.1 web app that was running perfectly for a long time. I recently used the new "Web Application Project" type to convert my v1.1 application to v2.0 Everything went smoothly...
20
by: Rio Liaden | last post by:
In another post requiring conversion, I could see how you helped the person, but my field is a bit different and I do not code well. My field is on a report and reads: =Sum(). It is comprised of...
1
by: tnt84 | last post by:
I want to write a program that reads a text file and prints out the word frequencies using structure but I don't know exactly what the word frequency is and how can I write that program using...
1
by: electroon | last post by:
Hi frnds, I have written a code to get current time struct tm *locTime; time_t currentTime; time( &currentTime ); locTime = localtime(&currentTime ); Suppose now i get output time as...
6
bajajv
by: bajajv | last post by:
Hi, My code is - void func1(void* arg) { printf("In child thread.\n"); } int main()
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.