need help.. calculator program..need to pass next week

hi everyone... I have a big problem about my calculator program plus I need to pass this next week and present and oral defense. Can somebody please help me on this. I have the code here. Thank you.Your help is highly appreciated. By the way i am using turbo c. Heres the instruction:
SIMPLE ARITHMETIC CALCULATOR
- Create a simple calculator program with the following output below.

1 2 3 + *
4 5 6 - /
7 8 9 ENTER
Output: _

- The number output will be shown in right justified format.
- Everytime a keyboard key is pressed, if it matches to any of the calculator keys, then the corresponding calculator key is highlighted. It remains highlighted until the user presses another key. If this key matches to any of the calculator keys, then the highlight is moved to that key.

- Arithmetic operation is performed when two numbers, the desired operator and the ENTER key are entered. The two numbers and result are shown one at a time in the output.
- When an operator key is selected, no output is shown or the existing output remains the same.
- When the user inputs other keys not in the calculator, the program will not do anything.
- When the user selects the minus sign followed by a number, the negative number is shown.
- The program will only terminate if the user pressed ESC ('x1B') key.


#include
#include
#include
int main()
{
int x,y,answer;
char operator;
clrscr();



printf("
*******************
");
printf("
CALCULATOR


");


printf("
*******************
");
printf("
* 1 2 3 + *

*
");
printf("
* 4 5 6 - /

*
");
printf("
* 7 8 9 0

Enter*
");


printf("
*******************
");
printf("
*

*
");


printf("
*******************
");
textcolor(15);
{gotoxy(1,8); cprint("Enter your

desired number:");
scanf("%d",&x);
}
if (x==7)
(textcolor (11+127);
gotoxy(1,1);
cprintf("7");
}
else if(x==8)
{textcolor(11+127);
gotoxy(3,1);
cprintf("8");
}
else if(x==9)
{textcolor(11+127);
gotoxy(5,1);
cprintf("9");
}
else if(x==4)
{
textcolor(11+127);
gotoxy(1,2);
cprintf("4");
}
else if(x==5)
{
textcolor(11+127);
gotoxy(3,2);
cprintf("5");
}
else if(x==6)
{textcolor(11+127);
gotoxy(5,2);
cprint("6");
}
else if(x==1)
{textcolor(11+127;)
gotoxy(1,3);
cprint("1");
}
else if(x==2)
{textcolor(11+127);
gotoxy(3,3);
cprintf("2");
}
else if(x==3)
{textcolor(11+127);
gotoxy(5,3);
cprintf("3");}
else if(x==0)
{textcolor(11+127);
gotoxy(3,4);
cprintf("0");
}
else
{textcolor(11+127);
gotoxy(1,10);
cprintf("digit shoul only be

one");}

textcolor(15);
gotoxy(1,9);
cprintf("Enter your desired

operator:");
scanf("%s",operator);

if oprtr=='-')
{
textcolor(11+127);
gotoxy(5,5);
cprintf("-");}
else if(oprtr=='+')
{textcolor(11+127);
gotoxy(1,5);}
else if (oprtr=='*')
{textcolor(11+127);
gotoxy(1,6);
cprintf("*");}
else if (oprtr=='/');
{textcolor(11+127);
gotoxy(5,6);
cprintf("/");
}
else
{textcolor(11+127);
gotoxy(1,12);
cprintf(("error! invalid");
}
textcolor(15);
{gotoxy(1,10); cprintf("Enter next

number: ");
scanf("%d",y);
}
if (y==7)
{textcolor(11+127);
gotoxy(1,1);
cprintf("7");}
else if (y==8)
{textcolor(11+127);
gotoxy(3,1);
cprintf("8");
}
else if(y==9){
textcolor(11+127);
gotoxy(5,1);
cprintf("9");}
else if(y==4){
textcolor(11+127);
gotoxy(1,2);
cprintf("4");}
else if (y==5){
textcolor(11+127);
gotoxy(3,2);
cprintf("5");}
else if(y==6){
textcolor(11+127);
gotoxy(5,2);
cprintf("6");}
else if(y==1){
textcolor(11+127);
gotoxy(1,3);
cprintf("1");}
else if(y==2)
{textcolor(11+127);
gotoxy(3,3);
cprintf("2");}
else if(y==3)
{textcolor(11+127);
gotoxy(5,3);
cprintf("3");}
else if(y==0){
textcolor(11+127;
gotoxy(3,4);
cprintf("0");}
else
textcolor(11+127);
gotoxy(1,10);
cprintf("one digit only");}
if (oprtr=='-')
{
ans=x-y;}
else if(oprtr=='+')
ans=x+y;}
else if(oprtr='*');
ans='x'*'y';}
else{
ans=x/y;}
textcolor(6);
{
gotoxy(1,11);
cprintf("result: %d",ans);
}
getche();
}

Comments

  • That is quite unreadable, I'm afraid. Please use code tags when posting code:

    [leftbr]code[rightbr]

    /* code goes here */

    [leftbr]/code[rightbr]

    will make the code appear like this:

    [code]int main ()
    {
    printf("Hello world");
    return 0;
    }
    [/code]
  • : That is quite unreadable, I'm afraid. Please use code tags when
    : posting code:
    :
    : [leftbr]code[rightbr]
    :
    : /* code goes here */
    :
    : [leftbr]/code[rightbr]
    :
    : will make the code appear like this:
    :
    : [code]: int main ()
    : {
    : printf("Hello world");
    : return 0;
    : }
    : [/code]:

    How do I make this program right.
    Can somebody please correct this one, cause i need to present this next week for our finals. Please????

  • : How do I make this program right.
    : Can somebody please correct this one, cause i need to present this
    : next week for our finals. Please????
    :

    Step 1) Tidy the formatting of the code by reposting it the way Lundin described (you could Edit your first post and surround the code by code tags).

    Step 2) /* This will be filled in as soon as you have reposted */
    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry

  • : Step 1) Tidy the formatting of the code by reposting it the way
    : Lundin described (you could Edit your first post and surround the
    : code by code tags).
    :
    : Step 2) /* This will be filled in as soon as you have reposted */
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry


    okay, i made another program and it works. But here's my problem, i need my program to have no DEFINE functions. How will do this in order for it to be readable. CAn somebodey please help. The deadline is almost there.
  • : Step 1) Tidy the formatting of the code by reposting it the way
    : Lundin described (you could Edit your first post and surround the
    : code by code tags).
    :
    : Step 2) /* This will be filled in as soon as you have reposted */
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry


    okay i made another program.But here's my problem, i need my program to have no DEFINE functons. How can i do this right? can somebody please help... The deadline is almost there. here's my code:

    #include
    #include
    #include


    #define h(x,y,a) gotoxy(x,y);textattr(BLUE<<4|YELLOW);cprintf(" %s ",a);gotoxy(80,25);
    #define normal(x,y,a) gotoxy(x,y);textattr(BLACK<<4|WHITE);cprintf(" %s ",a);gotoxy(80,25);

    #define normalize() normal(30,10,"1");normal(34,10,"2");normal(38,10,"3");normal(42,10,"+");normal(46,10,"*");
    normal(30,11,"4");normal(34,11,"5");normal(38,11,"6");normal(42,11,"-");normal(46,11,"/");
    normal(30,12,"7");normal(34,12,"8");normal(38,12,"9");normal(42,12,"0");normal(46,12,"ENTER");
    #define ncolor textattr(BLACK<<4|WHITE);

    #define keylight() if(ch=='1'){ h(30,10,"1");} else if(ch=='2'){ h(34,10,"2");} else if(ch=='3'){ h(38,10,"3");} else if(ch=='+'){ h(42,10,"+"); }
    else if(ch=='*'){ h(46,10,"*");} else if(ch=='4'){ h(30,11,"4");} else if(ch=='5'){ h(34,11,"5");}
    else if(ch=='6'){ h(38,11,"6");} else if(ch=='-'){ h(42,11,"-");} else if(ch=='/'){ h(46,11,"/");}
    else if(ch=='7'){ h(30,12,"7");} else if(ch=='8'){ h(34,12,"8");} else if(ch=='9'){ h(38,12,"9");} else if(ch=='0'){ h(42,12,"0"); }else if(ch==13) { h(46,12,"ENTER"); }

    #define tester() if(number1==0){number1=num*neg;}else if(number1!=0 && number2==0){number2=num*neg;}

    #define adjust if(temp<=9||temp==0){ x2=x-1; }else if(temp<=99){ x2=x-2; }else if(temp<=999){ x2=x-3; }else if(temp<=9999){ x2=x-4; }
    else if(temp<=99999){ x2=x-5; }else if(temp<=999999){ x2=x-6; }else if(temp<=9999999){ x2=x-7; }else if(temp<=99999999){ x2=x-8; }else if(temp<=999999999){ x2=x-9; }else if(temp<=9999999999){ x2=x-10; }
    else if(temp>=-9||temp==0){ x2=x-1; }else if(temp>=-99){ x2=x-2; }else if(temp>=-999){ x2=x-3; }else if(temp>=-9999){ x2=x-4; }else if(temp>=-99999){ x2=x-5; }else if(temp>=-999999){ x2=x-6; }
    else if(temp>=-9999999){ x2=x-7; }else if(temp>=-99999999){ x2=x-8; }else if(temp>=-999999999){ x2=x-9; }else if(temp>=-9999999999){ x2=x-10; }

    void main ()
    {
    int ch=0,total,x=52,p=0,nonzero=1,x2=0,neg=1;
    int accrec=0;
    double num=0,number1=0,number2=0,temp=0;




    clrscr();
    normalize();
    normal(30,14,"Output: ");


    while(ch!=27)
    {
    while(kbhit())
    {
    normalize();
    ch=getch();
    keylight();

    /**********[NUMS]************/

    if(ch=='0'&& num==0){ nonzero=0; } else nonzero=1;


    if(nonzero==1 && ch>='0' && ch<='9')
    {
    if(accrec==1)
    { gotoxy(38,14);ncolor;cprintf(" "); }


    if(x>=43)
    {
    num *=10;
    num +=(ch-'0');
    x--;
    gotoxy(x,14);ncolor;cprintf("%.0f
    ",num*neg);
    }
    }


    /*****[OPERATOR]************/
    if(ch=='/'|| ch=='*'||ch=='-'||ch=='+'||ch==13)
    {
    tester();
    accrec=1;
    num=0;
    x=52;
    if(ch=='+'){ p=1; } /* add */
    if(ch=='-'){ p=2; } /* minus */
    if(ch=='*'){ p=3; } /* times */
    if(ch=='/'){ p=4; } /* devide */

    /*******[ENTER]*********/
    if(ch==13)
    {
    if(number1!=0 || number2!=0)
    {
    gotoxy(38,14);ncolor;cprintf(" ");

    if(p==1)
    { temp=number1+number2; adjust; gotoxy(x2,14);ncolor;cprintf("%.0f",number1+number2); }
    if(p==2)
    { temp=number1-number2; adjust; gotoxy(x2,14);ncolor;cprintf("%.0f",number1-number2); }
    if(p==3)
    { temp=number1*number2; adjust; gotoxy(x2,14);ncolor;cprintf("%.0f",number1*number2); }
    if(p==4)
    { temp=number1/number2; adjust; gotoxy(x2-5,14);ncolor;cprintf("%.4f",(float)number1/number2); }
    }
    }
    }
    }/*kbhit for while */
    }/*escape for while */
    }/*end of main */

  • :
    : : Step 1) Tidy the formatting of the code by reposting it the way
    : : Lundin described (you could Edit your first post and surround the
    : : code by code tags).
    : :
    : : Step 2) /* This will be filled in as soon as you have reposted */
    : : Best Regards,
    : : Richard
    : :
    : : The way I see it... Well, it's all pretty blurry
    :
    :
    : okay, i made another program and it works. But here's my problem, i
    : need my program to have no DEFINE functions. How will do this in
    : order for it to be readable. CAn somebodey please help. The deadline
    : is almost there.
    :

    In that case, you'll want to do the "Play the preprocessor" game.
    The game goes like this: you browse through your program, and you fill in any preprocessor symbol with it's definition.
    And it's very simple too - just copy the part after the preprecessor symbol definition (eg #define symbol [italic]copy_this[/italic]) and paste it where this symbol occurs.

    But I looked at your code and your pre-processor definitions are BAD.
    Turn them into real functions, rather than doing the copy-'n-pasting thing.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • Removed the other thread with the same topic. Please don't double-post.
  • : Removed the other thread with the same topic. Please don't
    : double-post.


    Sorry for i've done. By the way, may I ask how to remove the thread of mine? thank you for the notice.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories