Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Development

Archive::Development Archive area for Development's posts that were moved here after an inactivity period of 90 days.

Reply
 
Thread Tools Display Modes
  #1  
Old 05-26-2004, 02:30 AM
maaltan
Fire Beetle
 
Join Date: May 2004
Posts: 9
Default calculator

a very simple calculator, im just typing it in here so you might have to correct some small compile errors, but the logic should be sound.
That would make a good debugging exercise for the trainees

I tried leaving pointers out of it .. but hell thats what c runs on you have to learn them eventually.

You will have to break out though its infinate

Code:
#include <stdio.h>

int main()
{
 float oprand; 
    float accumulator; 
    char buf=' ';

while (1) 
{ 
   printf("Enter a the first number\n"); 
   scanf("%f", &accumulator); 
   buf = ' ';
while (buf != '=') 
{
   
   printf("Enter +,-,*, /   Or enter = to get result\n");
   scanf("%s", &buf);

   if (buf != '=')
   {
	   printf("Enter next number.\n");
	   scanf("%f", &oprand);
   }

   switch (buf)
   {
        case '+':
               accumulator+=oprand;
			   break;
        case '-':
               accumulator-=oprand;
			   break;
        case '*':
               accumulator*=oprand;
			   break;
        case '/':
               accumulator/=oprand;
			   break;
        case '=':
                printf("Result: %f\n", accumulator);
				break;
        default:
            printf("invalid operator\n"); // have to have it to prevent the program from crashing, you may wish to put debugging info in here
    }

}
}

} // err lost track of braces this might not be needed
well its started out simple .. hope it helps actually it turned out to be c instead of c++ .. eeh it will work in c++ .. replace the printfs and scanfs with cin and cout stream redirections like your use to ..then it be c++
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 10:55 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3