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 make it posible that the user can input a decimal? i heard about floats , but cant ...

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

    decimals in calculator

    how do you make it posible that the user can input a decimal?
    i heard about floats , but cant find how-to
    for example
    Code:
    inline void vermenigvuldigen()
    {
          
    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();                
    }
    }

  2. #2
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    You can use data type of 'double' or 'float'.

    Declare as follows:

    Code:
    float hello1;
    Code:
    double hello1;
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    how do you put them in the code?

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    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();                
    }
    The parts in red are extremely poor design. You shouldn't be using recursion for a problem that calls for iteration. Rather than calling vermenigvuldigen, you should wrap the entire body of the function within a loop.

    The part in blue is illegal. Main cannot be called recursively in C++. You're relying on a quirk of your compiler. Even if it were legal, it would exhibit the same poor design as the parts in red.
    My best code is written with the delete key.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,302
    Have you considered learning C++ from the basics?

    By the way, it looks like you may have a recursive call to the global main() function, which is not allowed.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    just answer on my question
    i m just beginning and follewing the tutorials here
    but wants to experiment with a calculator

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    btw : IT'S JUST A PART OF THE CODE

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Get an attitude adjustment and try again.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GUI Calculator - Critique
    By The Brain in forum Windows Programming
    Replies: 1
    Last Post: 02-25-2006, 04:39 AM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 01:56 PM
  3. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 10:48 AM
  4. Java Calculator
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-12-2002, 08:39 PM
  5. Replies: 2
    Last Post: 05-10-2002, 05:16 PM

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