decimals in calculator

This is a discussion on decimals in calculator within the C++ Programming forums, part of the General Programming Boards category; how do you put them in Code: #include <iostream> #include <stdio.h> #include <string.h> #include <ctype.h> #include <math.h> #include <conio.h> #include ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    70

    decimals in calculator

    how do you put them in

    Code:
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    #include <math.h>
    #include <conio.h> 
    #include "global.h"
    
    double sqrt(double x);
    
    
    using namespace std;
    
    void vermenigvuldigen ();
    void optellen  ();
    void aftrekken () ;
    void delen ();
    void kwadrateren ();
    void vierkantswortel ();
    void credits ();
    
    
    void setcolor(unsigned short color) {	//begining of set color funtion
     HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);  	//gets std handle
     SetConsoleTextAttribute(hCon,color); 
    }
    int main (void) 
    {
    C.I = 4;    
    setcolor(C.I);  
        
    cout << " ______   _______   _        ______      \n";  
    cout << "|  ____| |  ___  | | |      |  ____|  \n";
    cout << "| |      |  | |  | | |      | |      \n";
    cout << "| |____  |  ---  | | |____  | |____ \n";
    cout << "|______| |__| |__| |______| |______| v0.041 Beta \n";
        int input;
        C.I = 6;    
        setcolor(C.I);  
        cout<<"1. Vermenigvuldig\n";
        cout<<"2. delen\n";
        cout<<"3. optellen\n";
        cout<<"4. aftrekken\n";
        cout<<"5. kwadrateren\n";
        cout<<"6. Vierkantswortel\n";
        cout<<"7. Credits , historie en To-Do\n";
        cout<<"8. sluiten\n";
        C.I = 7;
        setcolor(C.I);
        cout<<"selecteer:";
        cin>> input;
        switch (input) {
               case 1:
                   system("cls"); 
                
               vermenigvuldigen();
                    
               case 2 : 
               system("cls");          
               delen();
               case 3 :
                system("cls");    
                optellen();
               case 4 :
                  system("cls"); 
                    aftrekken();
               case 5 :
               system("cls"); 
                    kwadrateren ();
             case 6 :
              system("cls");
              vierkantswortel();           
              case 7 :
              system("cls");
              credits();     
                         
               case 8 :
              system("cls"); 
                    exit ( EXIT_FAILURE );//sluit af                   
               default:
                    system("cls");    
                    cout<<"error , slechte selectie , probeer opnieuw\n";
                    main();
    cin.get();
    }                                      
    
    
    
    } 
    
    
    inline void vermenigvuldigen()
    {
    float hello1;       
          
    int x;
    int y;
    C.I = 8;
    setcolor(C.I);
    
     cout<<"schrijf 2 getallen voor te vermenigvuldigen: ";
    cin>>x>>y;
    cin.ignore();
    cout<<"het produkt van de 2 getallen is ";
    C.I = 10;
    setcolor(C.I);
    cout<<x*y<<"\n";
    int input;
    C.I = 4;
    setcolor(C.I);
    cout<<"1.nog eens\n";
    cout<<"2.ga terug naar het hoofdmenu\n";
    cout<<"3.sluiten\n";
    cout<<"selectie";
    cin>>input;
    switch (input) {
           case 1:
                system("cls");
                vermenigvuldigen();
           case 2 : 
                  system("cls");
                  main();
          case 3 :
               system("cls");
               exit ( EXIT_FAILURE );//sluit af  
            default:
                    system("cls");    
                    cout<<"error , slechte selectie , probeer opnieuw\n";
                    vermenigvuldigen();                
    }
    }
    inline void optellen ()
    {
    int x;
    int y;
    C.I = 8;
    setcolor(C.I);
     cout<<"schrijf 2 getallen om optetellen: ";
    cin>>x>>y;
    cin.ignore();
    cout<<"de som van de 2 getallen is ";
    C.I = 10;
    setcolor(C.I);
    cout<<x+y<<"\n\n\n\n";
    int input;
    C.I = 4;
    setcolor(C.I);
    cout<<"1.nog eens\n";
    cout<<"2.ga terug naar het hoofdmenu\n";
    cout<<"3.sluiten\n";
    cout<<"selectie";
    cin>>input;
    switch (input) {
           case 1:
                system("cls");
                optellen();
           case 2 : 
                  system("cls");
                  main();
          case 3 :
               system("cls");
               exit ( EXIT_FAILURE );//sluit af  
             default:
                    system("cls");    
                    cout<<"error , slechte selectie , probeer opnieuw\n";
                    optellen();               
    }
    } 
      inline void delen ()
    {
    int x;
    int y;
    C.I = 8;
    setcolor(C.I);
     cout<<"schrijf 2 getallen om te delen: ";
    cin>>x>>y;
    cin.ignore();
    cout<<"het quotient van de 2 getallen is ";
    C.I = 10;
    setcolor(C.I);
    cout<<x/y<<"\n\n\n\n";
    int input;
    C.I = 4;
    setcolor(C.I);
    cout<<"1.nog eens\n";
    cout<<"2.ga terug naar het hoofdmenu\n";
    cout<<"3.sluiten\n";
    cout<<"selectie";
    cin>>input;
    switch (input) {
           case 1:
                system("cls");
                delen();
           case 2 : 
                  system("cls");
                  main();
          case 3 :
               system("cls");
              exit ( EXIT_FAILURE );//sluit af 
         default:
                    system("cls");    
                    cout<<"error , slechte selectie , probeer opnieuw\n";
                    delen();                    
    }
    }  
     inline void aftrekken ()
    {
    int x;
    int y;
    C.I = 8;
    setcolor(C.I);
     cout<<"schrijf 2 getallen om aftetrekken: ";
    cin>>x>>y;
    cin.ignore();
    cout<<"het verschil van de 2 getallen is ";
    C.I = 10;
    setcolor(C.I);
    cout<<x-y<<"\n\n\n\n";
    int input;
    C.I = 4;
    setcolor(C.I);
    cout<<"1.nog eens\n";
    cout<<"2.ga terug naar het hoofdmenu\n";
    cout<<"3.sluiten\n";
    cout<<"selectie";
    cin>>input;
    switch (input) {
           case 1:
                system("cls");
                aftrekken();
           case 2 : 
                  system("cls");
                  main();
          case 3 :
               system("cls");
               exit ( EXIT_FAILURE );//sluit af
          default:
                    system("cls");    
                    cout<<"error , slechte selectie , probeer opnieuw\n";
                    aftrekken();                   
    }
    } 
    inline void kwadrateren ()
    {
    int x;
    
    C.I = 8;
    setcolor(C.I);
     cout<<"schrijf een getal om te kwadrateren: ";
    cin>>x;
    cin.ignore();
    cout<<"het kwadraat van het getal is ";
    C.I = 10;
    setcolor(C.I);
    cout<<x*x<<"\n\n\n\n";
    int input;
    C.I = 4;
    setcolor(C.I);
    cout<<"1.nog eens\n";
    cout<<"2.ga terug naar het hoofdmenu\n";
    cout<<"3.sluiten\n";
    cout<<"selectie";
    cin>>input;
    switch (input) {
           case 1:
                system("cls");
                kwadrateren();
           case 2 : 
                  system("cls");
                  main();
          case 3 :
               system("cls");
               exit ( EXIT_FAILURE );//sluit af
              default:
                    system("cls");    
                    cout<<"error , slechte selectie , probeer opnieuw\n";
                    kwadrateren();               
    } 
    } 
     inline void vierkantswortel ()
    {
    int x;
    
    
    C.I = 8;
    setcolor(C.I);
     cout<<"schrijf een getal om de vierkantswortel van te berekenen: ";
    cin>>x;
    cin.ignore();
    cout<<"de vierkantswortel van het getal is ";
    C.I = 10;
    setcolor(C.I);
    cout<<sqrt (x)<<"\n\n\n\n";
    int input;
    C.I = 4;
    setcolor(C.I);
    cout<<"1.nog eens\n";
    cout<<"2.ga terug naar het hoofdmenu\n";
    cout<<"3.sluiten\n";
    cout<<"selectie";
    cin>>input;
    switch (input) {
           case 1:
                system("cls");
                vierkantswortel();
           case 2 : 
                  system("cls");
                  main();
          case 3 :
               system("cls");
               exit ( EXIT_FAILURE );//sluit af 
                      default:
                    system("cls");    
                    cout<<"error , slechte selectie , probeer opnieuw\n";
                    vierkantswortel();
                    }
    
    }    
    inline void credits ()
    {
           C.I = 8;
           setcolor(C.I);
    cout<<"                              A -=[RP]=- Production\n";
    cout<<"                                 Coded by Roel  \n\n\n";
    C.I = 7;
    setcolor(C.I);
    cout<<"Historie: \n";
    cout<<"v0.01 : verminigvuldigen test\n";
    cout<<"v0.02 andere bewerkingen erbijgevoegd na succesvolle test\n";
    cout<<"v0.03 menu toegevoegd ,waardoor niet alle bewerking worden uitgevoerd in 1 keer\n";
    cout<<"v0.031 : irritante sluit-bug gefixt\n";
    cout<<"v0.04 : text kleuren ingevoegd\n";
    cout<<"v0.041 : hergeschrijven source code en menu geuptaded\n\n\n";
    C.I = 6;
    setcolor(C.I);
    cout<<"To Do : \n";
    cout<<"v0.05 : komma getallen invoegen\n";
    cout<<"v0.06 : lay-out\n";
    cout<<"....\n";
    cout<<"v1.0 : port naar psp met ingebouwd toetsenbord\n\n\n"; 
    int input;
    C.I = 5;
    setcolor(C.I);
    cout<<"1. Ga terug\n";
    cout<<"2. sluiten\n";
    cout<<"selectie:";
    cin>> input;
        switch (input) {
               case 1:
                    system("cls");
                    main();
               case 2:
                    system("cls");                
                   exit ( EXIT_FAILURE );//sluit af
                    
                default:
                    system("cls");    
                    cout<<"error , slechte selectie , probeer opnieuw\n";
                    credits();
                    }
    cin.get();                   
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Context would be nice. I happen to know what you're talking about, but others might wonder that you asked a vague question and posted reams of code. Also, have you even tried to use double or float instead of int? Or are you asking us to do it for you?
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    i dont understand anything about float
    and no you dont have to do it for me , i cant learn it than , and thats not what i want

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >i dont understand anything about float
    You really don't need to understand. Just replace this:
    Code:
    int x;
    int y;
    With this:
    Code:
    double x;
    double y;
    As was already explained to you before you immediately shot back with a request for the exact steps of modifying your code.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    yeah srry i just cant good english.i give it a try

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    Comparing optellen () and delen() side by side is a revelation.
    I suspect the same is true for a few other functions as well.

    > cout << "| ____| | ___ | | | | ____| \n";
    As a rule, avoid cluttering up the program with trivial presentation code until the substance actually works properly. It's less code to look at, less code for us to wade through when it goes wrong.

    > system("cls");
    Check the FAQ for better ways of clearing the screen.

    > system("cls");
    > main();
    Calling main() recursively is a no-no.
    Use proper loop constructs if you want to repeat stuff.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    oke it works
    big thnx

    you can lock this trhead

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. decimals in calculator
    By hallo007 in forum C++ Programming
    Replies: 7
    Last Post: 09-24-2006, 10:14 AM
  2. GUI Calculator - Critique
    By The Brain in forum Windows Programming
    Replies: 1
    Last Post: 02-25-2006, 03:39 AM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 09:48 AM
  5. Replies: 2
    Last Post: 05-10-2002, 04:16 PM

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