All pastes #111023 Raw Edit

Devon Klosterman

public c v1 · immutable
·published 2006-08-02 02:45 UTC
rendered paste body
#include <stdio.h>#include <conio.h>#include <math.h>#include <string.h>char result[20]; // declares character string resultint type; int first = 0;float mainhold;float maincur;int end = 0;char yesno[10];int quit = 0;char Y[] = "Y";char Yes[] = "Yes";char YES[] = "YES";char yes[] = "yes";char y[] = "y";char N[] = "N";char No[] = "No";int main(){void add(){             float sumhold; // declares the variable to hold the current total             float sumcur; // declares the variable to hold the next value being added             strcpy(result, "Sum");             if (first == 0)             {                                              printf(" Enter first number\n");                       scanf(" %f", &sumhold );                       mainhold = sumhold;                       first++;                       }                                  printf(" Enter number to be added\n");                 scanf(" %f", &sumcur );                                  if (first == 0)                 {                           mainhold = sumcur + sumhold;                           }                 else                 {                     mainhold = mainhold + sumcur;                      } // ends addition section                     }void sub()    {             float subhold; // declares the variable to hold the current total             float subcur; // declares the variable to hold the next value being added             strcpy(result, "Difference");             if (first == 0)             {                                              printf(" Enter first number\n");                       scanf(" %f", &subhold );                       mainhold = subhold;                       first++;                       }                                  printf(" Enter number to subtract\n");                 scanf(" %f", &subcur );                                  if (first == 0)                 {                           mainhold = subcur - subhold;                           }                 else                 {                     mainhold = mainhold - subcur;                     }                     } // ends subtraction section    void mult() {             float multhold; // declares the variable to hold the current total             float multcur; // declares the variable to hold the next value being added             strcpy(result, "Product");             if (first == 0)             {                                              printf(" Enter first number\n");                       scanf(" %f", &multhold );                       mainhold = multhold;                       first++;                       }                                  printf(" Enter number to be multiplied\n");                 scanf(" %f", &multcur );                                  if (first == 0)                 {                           mainhold = multcur * multhold;                           }                 else                 {                     mainhold = mainhold * multcur;                     }                     } // ends multiplication section         void div(){             float divhold; // declares the variable to hold the current total             float divcur; // declares the variable to hold the next value being added             strcpy(result, "Quotient");             if (first == 0)             {                                              printf(" Enter first number\n");                       scanf(" %f", &divhold );                       mainhold = divhold;                       first++;                       }                                  printf(" Enter number to divide by\n");                 scanf(" %f", &divcur );                                  if (divcur != 0)                 {                 if (first == 0)                 {                           mainhold = divcur / divhold;                           }                 else                 {                     mainhold = mainhold / divcur;                     }                     }                     else                     {                         printf(" Can not divide by zero\n");                         printf(" Press any key to continue\n\n");                         getch();  // How I set it to clear everything without using a goto?                                                 }                     } // ends division section                          void root() {             float roothold; // declares the variable to hold the current total             float rootcur; // declares the variable to hold the next value being added             strcpy(result, "Square root");             if (first == 0)             {                                              printf(" Enter first number\n");                       scanf(" %f", &roothold );                       mainhold = roothold;                       first++;                       }                                  if (first == 0)                 {                           mainhold = sqrt(roothold);                           }                 else                 {                     mainhold = sqrt(mainhold);                     }                     } // ends square root sectionvoid expo(){float expa;float base;float expaend;int expcount;      printf( "Enter numerical base\n"); /* asks user to enter numerical base */      scanf(" %f", &base); /* assigns the variable "base" a value */      printf( "Enter numerical exponant\n"); /* requests value of exponant */      scanf(" %f", &expa); /* assigns the variable "expa" a value */            if ((expa == 0) || (expa == 1)) /* deals with exponants one and zero */      {      if (expa == 0) /* deals with something to the zero power */      {              (expaend = 1); /* assigns "basenot" to the zero power as having the value of one */      }      else {           (expaend = base); /* assigns "base" to the first power a value of itself */           }           }           else {                (expaend = base); /* starts end at the value of base */                for (expcount = 2; expcount <= expa; expcount++) /* from 2 = expcount <= expa, do a loop */      {          expaend = (expaend * base);          }          }          printf( "%f to the %f power is %f\n", base, expa, expaend);          mainhold = expaend;                       } // ends exponant sectionwhile (quit == 0){while (end == 0) // begins the main while statement{    printf(" Type the number that matches the type of calcuation\n ");    printf(" 1 Addition\n ");    printf(" 2 Subtraction\n ");    printf(" 3 Multiplication\n ");    printf(" 4 Division\n ");    printf(" 5 Square Root\n ");    printf(" 6 Exponants\n ");    printf(" 7 Fractional Exponants\n ");    printf(" 8 Exit Program\n "); // Don't forget to change the quit value when adding additional features    scanf(" %d", &type );        if (type == 1)    {       add();                     } // ends adddition section                         if (type == 2){    sub();}                                                       if (type == 3)   {       mult();       }                                                                if (type == 4)    {             div();             }    if (type == 5)   {       root();       }                         if (type == 6) // begins exponant section    {             expo();             }                   if (type == 8) // begins quit section      {               end++;               quit++;               } // ends quit section                          if ((type >= 1 && type <= 3) || (type >= 5 && type <= 7)) // Don't forget to modify this when adding additional features             {             if ((type >= 1 && type <= 3) || (type <= 5)) // Don't forget to modify this when adding additional features             {                     printf(" %s is %f\n", result, mainhold); // prints result for any of the first five except division             }              printf(" Perform additional operation to current number? (Y/N)\n");             scanf(" %s", &yesno );             if ((strcasecmp (yesno,N) == 0) || (strcasecmp (yesno,No) == 0))             {                                end++;                                }                                }                                } //ends main while statement             end--;             first = 0;             } // ends final while statement             return 0;             }