Input help.

closed account (SEbXoG1T)
I have a program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Define LibPub days(m,d,y)=
Prgm
Local day, yt5,ye
yt5:=y*5
If  m=1 Then
ye:= 1
EndIf
If  m=2 Then
ye:=4
EndIf
If  m=3 Then
ye:=4
EndIf
If  m=4 Then
y:=0
EndIf
If  m=5 Then
y:=2
EndIf
If  m=6 Then
y:=5
EndIf
If  m=7 Then
ye:=0
EndIf
If  m=8 Then
ye:=3
EndIf
If  m=9 Then
ye:=6
EndIf
If  m=10 Then
ye:=6
EndIf
If  m=11 Then
ye:=4
EndIf
If  m=12 Then
ye:=6
EndIf
day:=approx({intDiv[yt5,4]+ye+d}/7)
Disp day
EndPrgm

This language is a variation of basic. It outputs a number eg. 20.57198 but the problem with input is that i only need the first number past the decimal. Questions on syntax and meaning will be answered. thank you.
Are you looking for a translation of this to C++, and then the C++ solution to obtaining the integer part of the number?
I do not understand your question. Do you need help with the language or as webJose said on the translation?
closed account (SEbXoG1T)
no, i am looking for how i would take the .5 from 20.57 in C++, then i should be able to translate it
oh okay
1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;
int main ()
{
       float MyFloat = 20.57 -  0.5;
       cout << MyFloat << endl;
       cout << "Press ENTER to end the program." << endl;
       cin.get ();
       return 0;
}

is this what you want?
If you need truncation of the decimal part:

1
2
3
4
float myFloat = 20.57;
cout << myFloat << endl;
int myInt = int(myFloat);
cout << myInt <<endl;
closed account (DSLq5Di1)
If I understood correctly.. OP just wants the first digit after the decimal point,

1
2
3
4
inline int frac_nth_digit(double num, int digit)
{
    return static_cast<int>( fmod(num * pow(10.0, digit), 10) );
}

cout << frac_nth_digit(20.57198, 1);

5
closed account (SEbXoG1T)
yes, i just want the first digit past the decimal
closed account (SEbXoG1T)
but is there a way you could translate that to basic?
closed account (DSLq5Di1)
20.57198 * 10 = 205.7198
205.7198 % 10 = 5.7198
5
The % (Modulo) operator returns the remainder of division in C.

http://tibasicdev.wikidot.com/remainder
http://tibasicdev.wikidot.com/ipart
closed account (SEbXoG1T)
nope, neither work
closed account (SEbXoG1T)
Wait, no never mind i added this
1
2
d1:=day*10
d2:=int(mod{d1,10})

Thank you all
closed account (SEbXoG1T)
The modulus is extremely inaccurate. need a more accurate method
Topic archived. No new replies allowed.