ID:153536
 
Alright, for a High School C++ class I'm assisting in teaching I'm introducing BYOND and the DM language to them.
So to my question, can someone convert this to DM in the simplist way possible?
#include<iostream.h>
int main()
{
int A, B, C;
cout<<"-Simple Addition Program-"<<endl;
cout<<"Enter the first number you would like to add: ";
cin>>A;
cout<<"Enter the second number you would like to add: ";
cin>>B;
C=A+B;
cout<<A<<" + "<<B<<" = "<<C<<endl;
return 0;
}

Thanks!

ETG
Erdrickthegreat2 wrote:
Alright, for a High School C++ class I'm assisting in teaching I'm introducing BYOND and the DM language to them.
So to my question, can someone convert this to DM in the simplist way possible?
> #include<iostream.h>
> int main()
> {
> int A, B, C;
> cout<<"-Simple Addition Program-"<<endl;
> cout<<"Enter the first number you would like to add: ";
> cin>>A;
> cout<<"Enter the second number you would like to add: ";
> cin>>B;
> C=A+B;
> cout<<A<<" + "<<B<<" = "<<C<<endl;
> return 0;
> }
>

Thanks!

ETG
mob/Login()
var
A;B;C
src<<"-Simple Addition Program-"
A=input("Enter the first number you would like to add:")as num
B=input(<<"Enter the second number you would like to add:")
C=A+B
src<<"[A] + [B] = [C]"

[edit]
If you wanted to create a c++ type of environment on byond, you could do something like this:
client/New()
.=..()
main()
client/proc/main()
//Do stuff here as you would in c++
del(src)

del(src)is instead of return 0, and so long as it is within a function belonging to the client, it will terminate the client from the program. In a single-user byond environment which is not hosted with Dream Daemon, but rather with Dream Seeker (The same window that you are using to use the program.) it will terminate the program in the same way.
Erdrickthegreat2 wrote:
Alright, for a High School C++ class I'm assisting in teaching I'm introducing BYOND and the DM language to them.
So to my question, can someone convert this to DM in the simplist way possible?
> #include<iostream.h>
> int main()
> {
> int A, B, C;
> cout<<"-Simple Addition Program-"<<endl;
> cout<<"Enter the first number you would like to add: ";
> cin>>A;
> cout<<"Enter the second number you would like to add: ";
> cin>>B;
> C=A+B;
> cout<<A<<" + "<<B<<" = "<<C<<endl;
> return 0;
> }
>

Thanks!

ETG

i thought it should be void main() for c++ instead of int main().

for all int, chars, float, and all those placeholders in c/c++, use var in dm.

cout<<"text"; --> usr<<"test"
cin>>A; --> input("A") as num
c=a_b --> same thing in DM
return --> same thing in DM

basically, in DM, you don't put a ; after each line and you don't need to put brackets, you use the tabs which i use cause its more cleaner for me. lol
In response to ZDarkGoku
ZDarkGoku wrote:
i thought it should be void main() for c++ instead of int main().

for all int, chars, float, and all those placeholders in c/c++, use var in dm.

cout<<"text"; --> usr<<"test"
cin>>A; --> input("A") as num
c=a_b --> same thing in DM
return --> same thing in DM

basically, in DM, you don't put a ; after each line and you don't need to put brackets, you use the tabs which i use cause its more cleaner for me. lol

"A=input("text")as num" would be closer to what he wants than "usr<<"text";input("A")as num". "cin>>A;" does not tell you the name of the variable you are inputting to, it just lets you type something in without telling you what for. That is why he has the cout<<"text" before it, which leaves text in front of the input field letting the user know what is needed. This would be basically like A=input("text")as num.

And about using tabs instead of brackets, you use tabs in c++, and you can use brackets in byond though they are not needed.

As for needing void main() instead of int main(), technically you are supposed to return 0 to the operating system when your program execution is done. But with one of the std libraries there is a end function that allows you to terminate the program from outside main(). When I am programming using c++, I usually use int main() and add the arguments for main() as well.
In response to Loduwijk
Loduwijk wrote:
And about using tabs instead of brackets, you use tabs in c++

No you don't. You use brackets.
In response to Alathon
but u dont have to
In response to ZDarkGoku
Yes you do. C++ requires brackets. DM doesn't.
In response to Crispy
Yes you do. C++ requires brackets. DM doesn't.

They're called braces :). Just had to point that out since it's been annoying me the whole thread. Brackets are [] not {}.
In response to Theodis
Theodis wrote:
Yes you do. C++ requires brackets. DM doesn't.

They're called braces :).

I know. I was just referring to them the way everyone else was. =)
In response to Crispy
lol. i was talking about that c++ does requires but DM doesn't. but in some cases, you don't have to use brackets in c++.
In response to ZDarkGoku
Braces aren't needed in certain aspects of C++
such as simple if() procs

ex:

#include<iostream.h>
int main()
{
int A;
cout<<"What is the temperature in F?";
cin>>A;

if(A>32)

cout<<"it is above freezing outside"<<endl;

else if(A<32)

cout<<"it is below freezing outside"<<endl;
else
cout<<"it is freezing outside"<<endl;
return 0;
}

or

#include<iostream.h>
int main()
{
int A;
cout<<"What is the temperature in F?";
cin>>A;

if(A>32)
{
cout<<"it is above freezing outside"<<endl;
}
else if(A<32)
{
cout<<"it is below freezing outside"<<endl;
}
else
{
cout<<"it is freezing outside"<<endl;
}
return 0;
}

I personally prefer using braces in if() procs, I'm more comfortable with them and they have a neater appearance.

Trog
In response to Troglodyte
Not to mention that by making it a habit, your code is more easily read. It's obvious where this if() begins and ends as opposed to this if().
In response to Alathon
Alathon wrote:
Loduwijk wrote:
And about using tabs instead of brackets, you use tabs in c++

No you don't. You use brackets.

I never said you don't use brackets, all I said is that you use tabs. And I am correct in that, at least I have never seen anyone's code for c++ be tabless. Tabs are used in c++ the same way they are in DM.
In response to Loduwijk
Not quite. DM uses tabs in the way that C++ uses braces and semi-colons. Tabs tell DM where one instruction ends and the next begins, and performs the function of grouping commands (for things like loops, etc).

C++ uses tabs for human formatting, that's all. You can write an entire C++ program on one line.
In response to Loduwijk
I see a bit of misunderstanding here that I feel the need to clear up:

The statement, "And about using tabs instead of brackets, you use tabs in c++" is interpretted as, "you use tabs instead of brackets"... Of course, we now see that this isn't what you really meant to say, but from the way it was worded, that is the way it comes across...

A better wording would have been, "And about using tabs instead of brackets, you use both in c++"


In response to sapphiremagus
sapphiremagus wrote:
C++ uses tabs for human formatting, that's all. You can write an entire C++ program on one line.

You can also write an entire BYOND program on one line.
In response to OneFishDown
char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}getch();";ma in(){printf(s,34,s,34);getch();}

;) My one liner hack for C
In response to Loduwijk
...I think this wins my Most Trivial Subthread award. =)
In response to Spuzzum
I didn't even know you had a Most Trivial Subthread award. Still, now is an extremely apt time to invent one. =P
In response to Crispy
Better still, I now nominate this for the "Most Trivial Sub-subthread" award...
Page: 1 2