Need help with my program, please take a look

This is a discussion on Need help with my program, please take a look within the C++ Programming forums, part of the General Programming Boards category; I am working on a program that is supposed to get the result from a script(based on PL/0). For example: ...

  1. #1
    Registered User Hermisky's Avatar
    Join Date
    Feb 2006
    Location
    Nanjing
    Posts
    16

    Need help with my program, please take a look

    I am working on a program that is supposed to get the result from a script(based on PL/0).

    For example:
    if the script below is enterd into my program
    Code:
    program main;
    var id1,id2,id3;
    	begin
    	id1=1;
    	id2=1500;
    	id3=0;
    	while id2>100 do
    		begin
    		id2=id2-id1;
    		id3=id3+1;
    		end;
    	end
    .
    then my program would get the result:
    id3=1400,id2=100,id1=1
    and so far, it is correct.



    but when the script changes into this, bad things happened
    Code:
    program main;
    var id1,id2,id3;
    	begin
    	id1=0.01;
    	id2=5;
    	id3=0;
    	while id2>0 do
    		begin
    		id2=id2-id1;
    		id3=id3+1;
    		end;
    	end
    .
    my program gave me a weird answer:
    id3=501,id2=-0.01,id1=0.01
    the while statement has run one more time than it should be.

    And that is not all, if i initialize the id2 to 1 in the script above.
    Code:
    program main;
    var id1,id2,id3;
    	begin
    	id1=0.01;
    	id2=1;
    	id3=0;
    	while id2>0 do
    		begin
    		id2=id2-id1;
    		id3=id3+1;
    		end;
    	end
    .
    The result turned to "id3=100,id2=-7.5287e-16,id1=0.01".
    how could the id2 be "-7.5287e-16"?

    Could anyone tell me where the problem is? It really got me confused.
    Thanks
    Last edited by Hermisky; 02-02-2006 at 09:15 AM.

  2. #2
    Registered User Hermisky's Avatar
    Join Date
    Feb 2006
    Location
    Nanjing
    Posts
    16
    There are the three files in my program ,winman.cpp ,resource.h and resource.rc

    My compiler is CBuilderX 1.0

    The resource.rc file is this
    Code:
    //---------------------------------------------------------------------------
    // resource.rc
    //---------------------------------------------------------------------------
    
    #include "resource.h"
    
    
    IDR_MYMENU MENU DISCARDABLE
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "&New...",                       ID_FILE_NEW
            MENUITEM "&Open...",                       ID_FILE_OPEN
            MENUITEM "&Save",                       ID_FILE_SAVE
            MENUITEM "Save &As...",                       ID_FILE_SAVEAS
            MENUITEM SEPARATOR
            MENUITEM "E&xit",                       ID_FILE_EXIT
        END
        POPUP "&Edit"
        BEGIN
            MENUITEM "&Undo",                       ID_EDIT_UNDO
            MENUITEM SEPARATOR
            MENUITEM "Cu&t",                       ID_EDIT_CUT
            MENUITEM "&Copy",                       ID_EDIT_COPY
            MENUITEM "&Paste",                       ID_EDIT_PASTE
            MENUITEM "&Delete",                       ID_EDIT_DELETE
        END
        POPUP "&Analyse"
        BEGIN
            MENUITEM "&Word Analyse"      ID_ANALYSE_1 
            MENUITEM "Get &Result"      ID_ANALYSE_2 
        END
        POPUP "&Window"
        BEGIN
            MENUITEM "&New Window"      ID_WINDOW_NEW
        END
        POPUP "&Help"
        BEGIN
            MENUITEM "&About..."      ID_HELP_ABOUT
        END
    END
    
    IDI_MYICON              ICON    DISCARDABLE     "icon\\Notepad.ico"
    
    
    IDD_ABOUT DIALOG DISCARDABLE 50,30,250,80
    STYLE DS_MODALFRAME|WS_POPUP|WS_CAPTION|WS_SYSMENU
    CAPTION "Script Analyse"
    FONT 8,"MS Sans Serif"
    BEGIN
    DEFPUSHBUTTON "&OK",IDOK,100,55,50,15
    GROUPBOX "",IDC_STATIC,5,5,240,70
    CTEXT "i need help",IDC_STATIC,10,15,220,30
    END
    
    
    ID_DLG_ANALYSE DIALOG DISCARDABLE 260,100,150,300
    STYLE DS_MODALFRAME|WS_POPUP|WS_CAPTION|WS_SYSMENU
    CAPTION "Word analyse:"
    FONT 8,"MS Sans Serif"
    BEGIN
    EDITTEXT ID_EDIT_ANALYSE,5,5,140,290,ES_MULTILINE | WS_VSCROLL | ES_READONLY |NOT WS_BORDER,WS_EX_STATICEDGE
    END
    Attached Files Attached Files

  3. #3
    Registered User Hermisky's Avatar
    Join Date
    Feb 2006
    Location
    Nanjing
    Posts
    16
    and here is the exe file.
    change the file type to exe.
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21