My programs issues

pascal111 judas.the.messiah.111 at gmail.com
Wed Aug 10 13:34:53 UTC 2022


On Wednesday, 10 August 2022 at 13:13:20 UTC, Adam D Ruppe wrote:
> On Wednesday, 10 August 2022 at 12:36:42 UTC, pascal111 wrote:
>> 1) I used "exit()" from "core.stdc.stdlib;" module, but 
>> someone can say this isn't the D way to exit the program.
>
> It is better to simply return a value from main instead.
>
>> 2) I used "goto", I heard from someone before that using 
>> "goto" isn't good programming feature.
>
> Don't listen to people who are wrong.

So, the program will be like this:

'''D

module proj07;

import std.stdio;
import std.algorithm;
import std.range;

int main()
{

     double x, y;
     int choice;

new_again:

     x=0;
     y=0;

     write("Enter a number: ");
     readf(" %s\n", &x);
     y=x;
     writeln;

choice_again:

     writeln("1) addition 2) subtraction 3)
     multiplication 4) division 0) exit -1) new");
     ": ".write;

     readf(" %s\n", &choice);

     if(!only(1,2,3,4,0,-1).canFind(choice))
         goto choice_again;
     else if(choice==0)
         return 0;
     else if(choice==-1)
         goto new_again;

     write("Enter a number: ");
     readf(" %s\n", &x);

     switch(choice){

         case 1: y+=x; break;
         case 2: y-=x; break;
         case 3: y*=x; break;
         case 4: y/=x; break;
         default: break;}

     y.writeln;

     goto choice_again;

}

'''


More information about the Digitalmars-d-learn mailing list