C programming dilema
- Propyro
- Joined: Tue Mar 11, 2003 9:09 am
- Location: Ontario
C programming dilema
ok, i'm stuck ... i've got three simple programs that need to be done by midnight.
The first problem is a program that will take a 5 digit number, isolate the digits, and add them together. The 5 digit number must be one variable though.
I can get the first digit easily ... jsut divide by 10000. but it's the other digits that are pissing me off because i can't seem to get the formula to work with a random 5 digit number. And i know this is easy but ... fucking hell i can't remember shit about programming any more.
second problem ... i have to make a time counter.
i input one time in 24 hour time and a second one in 24 hour time. then it tells me if they are valid times, and tells me teh difference between them.
The third probram is a number mirroring program. i give it a 3 digit number, then i give it anohter, and it will tell me if it is a mirror of the first number. (ie. is in revers order.) I can only use one variable for this.
man this sucks ... these are easy programs but i can't remember shit for the life of me. And yes, i was trying to get this stuff done while i was posting ... but i suck at programming despite how much i like it.
I'm not asking you to give me the code, but if you can give me a hand it would be nice.
[/|\]
The first problem is a program that will take a 5 digit number, isolate the digits, and add them together. The 5 digit number must be one variable though.
I can get the first digit easily ... jsut divide by 10000. but it's the other digits that are pissing me off because i can't seem to get the formula to work with a random 5 digit number. And i know this is easy but ... fucking hell i can't remember shit about programming any more.
second problem ... i have to make a time counter.
i input one time in 24 hour time and a second one in 24 hour time. then it tells me if they are valid times, and tells me teh difference between them.
The third probram is a number mirroring program. i give it a 3 digit number, then i give it anohter, and it will tell me if it is a mirror of the first number. (ie. is in revers order.) I can only use one variable for this.
man this sucks ... these are easy programs but i can't remember shit for the life of me. And yes, i was trying to get this stuff done while i was posting ... but i suck at programming despite how much i like it.
I'm not asking you to give me the code, but if you can give me a hand it would be nice.
[/|\]
- madmag9999
- Joined: Sun Aug 10, 2003 11:50 pm
- Status: Engaged
- Location: Pennsylvania
problem 1:
u could take the number in as a string then do damn i forget what its called but there is a thing that makes it find the number in the specifided space of the string then u save it as a int and then repeat the process for all 5 numbers in the string then add them
u could take the number in as a string then do damn i forget what its called but there is a thing that makes it find the number in the specifided space of the string then u save it as a int and then repeat the process for all 5 numbers in the string then add them
Moonslayer's Guide to a-m-v.org | AD & ErMaC's Guides to Audio & Video
"I'm sorry but i don't trust anything that bleeds for 5 days and doesn't die."
"I'm sorry but i don't trust anything that bleeds for 5 days and doesn't die."
- madmag9999
- Joined: Sun Aug 10, 2003 11:50 pm
- Status: Engaged
- Location: Pennsylvania
problem 3:
also input it as a string then do what i said to do to the first one (find the numbers in the string and save them as int's) then add multiple the last int by 100 the second one 10 and leave the first one alone then add them and save them as a string then comepare the two strings
also input it as a string then do what i said to do to the first one (find the numbers in the string and save them as int's) then add multiple the last int by 100 the second one 10 and leave the first one alone then add them and save them as a string then comepare the two strings
Moonslayer's Guide to a-m-v.org | AD & ErMaC's Guides to Audio & Video
"I'm sorry but i don't trust anything that bleeds for 5 days and doesn't die."
"I'm sorry but i don't trust anything that bleeds for 5 days and doesn't die."
- madmag9999
- Joined: Sun Aug 10, 2003 11:50 pm
- Status: Engaged
- Location: Pennsylvania
http://cplus.about.com/library/weekly/aa051202a.htm there is a nice little tutorial on strings for u so u can find out how to find the postion in the string. if i remember correctly its string positon something eh the tutorial should have it
Moonslayer's Guide to a-m-v.org | AD & ErMaC's Guides to Audio & Video
"I'm sorry but i don't trust anything that bleeds for 5 days and doesn't die."
"I'm sorry but i don't trust anything that bleeds for 5 days and doesn't die."
- dokidoki
- c0d3 m0nk3y
- Joined: Tue Dec 19, 2000 7:42 pm
- Status: BLEEP BLOOP!
- Location: doki doki space
- Contact:
Are you allowed to convert them to strings or do you have to keep them as numbers?
An important operator for the first (and can be useful in the others) is the modulus/remainder ("mod") operator. It gives you the remainder of a division. It's represented by the percent sign. (%)
ie:
98 / 10 = 9
98 % 10 = 8
An important operator for the first (and can be useful in the others) is the modulus/remainder ("mod") operator. It gives you the remainder of a division. It's represented by the percent sign. (%)
ie:
98 / 10 = 9
98 % 10 = 8
- madmag9999
- Joined: Sun Aug 10, 2003 11:50 pm
- Status: Engaged
- Location: Pennsylvania
problem 2:
to find if they are valid u would need to divide the hours by 12 and if its <= 12 then its valid and the mintes by 60 and if its < 60 then its valid and then same for the seconds. then to compare them take time #1 and divide the hours by 60 then add it to the minutes and multply the seconds by 60 and add to the minutes do the same to time #2 then compare the two int's that u converted into minutes
to find if they are valid u would need to divide the hours by 12 and if its <= 12 then its valid and the mintes by 60 and if its < 60 then its valid and then same for the seconds. then to compare them take time #1 and divide the hours by 60 then add it to the minutes and multply the seconds by 60 and add to the minutes do the same to time #2 then compare the two int's that u converted into minutes
Moonslayer's Guide to a-m-v.org | AD & ErMaC's Guides to Audio & Video
"I'm sorry but i don't trust anything that bleeds for 5 days and doesn't die."
"I'm sorry but i don't trust anything that bleeds for 5 days and doesn't die."
- Propyro
- Joined: Tue Mar 11, 2003 9:09 am
- Location: Ontario
well i don't think weve gotten to strings yet in class, but if we could get it to wrok with strings then it's still ok. Also i forgot about the modulus function ... like i said ... insomnia is killing me ...
[/|\]
i don't know, we haven't covered strings yet. But i'll read the tutorial.madmag wrote:problem 1:
u could take the number in as a string then do damn i forget what its called but there is a thing that makes it find the number in the specifided space of the string then u save it as a int and then repeat the process for all 5 numbers in the string then add them
[/|\]
- madmag9999
- Joined: Sun Aug 10, 2003 11:50 pm
- Status: Engaged
- Location: Pennsylvania
o yea ummmmm that would change alot. ill try to find a c tutorial for u sorry bout that
Moonslayer's Guide to a-m-v.org | AD & ErMaC's Guides to Audio & Video
"I'm sorry but i don't trust anything that bleeds for 5 days and doesn't die."
"I'm sorry but i don't trust anything that bleeds for 5 days and doesn't die."