c/c++ clock like , battery charging


 
Thread Tools Search this Thread
Top Forums Programming c/c++ clock like , battery charging
# 1  
Old 10-28-2011
c/c++ clock like , battery charging

Hi all ,

I need to make a program who describes this ( upper ) graphic:
http://upload.wikimedia.org/wikipedi...-td_and_fd.png

My idea is to implement a battery charge
x: 0 to time T,
y : 0 to 1 values.

Can you help me ?
# 2  
Old 10-28-2011
That can be done by modulous, %, which gives the remainder of a / b. You have to do this as integers, but then you can convert by floating point and divide by T to get the number you want.

Code:
$ cat mod.c
#include <stdio.h>

int main(void)
{
        int x;
        int t=10;
        for(x=0; x<t*2; x++)
        {
                double y=(x%t)/(double)t;
                printf("%d\t%f\n", x, y);
        }
}

$ gcc mod.c
$ ./a.out
0       0.000000
1       0.100000
2       0.200000
3       0.300000
4       0.400000
5       0.500000
6       0.600000
7       0.700000
8       0.800000
9       0.900000
10      0.000000
11      0.100000
12      0.200000
13      0.300000
14      0.400000
15      0.500000
16      0.600000
17      0.700000
18      0.800000
19      0.900000
$


Last edited by Corona688; 10-28-2011 at 02:32 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Hardware

Forcing Linux to keep charging my Kindle

Linux seems to have weird USB power saving features, my Kindle 3 only gets some charge before Linux powers down the USB port. When the device is mounted, it doesn't get enough power, with this same hardware under Windows I don't get the message on the Kindle "currently your kindle is not... (2 Replies)
Discussion started by: John Tate
2 Replies

2. Linux

Battery always 0%

Im running Ubuntu 9.04 and the battery indicator on my laptop always reads 0% no matter what. Whether im charging or discharging, the pop up says: "Computer is running on battery power Laptop battery discharging (0.0%) Battery discharge time is currently unknown" When plugged in it says... (2 Replies)
Discussion started by: Charbs
2 Replies

3. Solaris

SE 3510 Battery Issue

Hi everyone, I changed the batteries on 29-Jun-2008 for the storedges. But received error messages from the server today,I used the "-u" option to update the service date information but it syntaticaly fails. Why? Jul 4 12:00:03 auriga SUNWscsdServer: <rctrl8001> The battery on... (3 Replies)
Discussion started by: incredible
3 Replies

4. UNIX for Dummies Questions & Answers

Charging for Linux?

Hello, Just been browsing Linux sites and have been coming across alot of news articles saying that Unix/Linux will no longer be free or open source anymore. Anyone else heard anything like this? It's a bit worrying. I have already seen example like that with Redhat I think. Is Linux... (1 Reply)
Discussion started by: ArkNia
1 Replies

5. UNIX for Dummies Questions & Answers

A1000 Battery Question

After searching and finding the link to the A1000 pdf ( http://192.18.99.138/805-7147/805-7147.pdf ) my questions are: 1) I have a battery failure on a A1000. I know that caching is disabled and it reports to see log. After reading the manual I have learned that the battery is a data-cache... (2 Replies)
Discussion started by: finster
2 Replies
Login or Register to Ask a Question