Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++]My longest code and my best creation so far
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Fri Feb 01, 2008 4:49 pm    Post subject: Reply with quote

You don't need to add a bunch of cases, when a div by 0 occurs an exception is thrown and you can catch that.
Back to top
View user's profile Send private message
BEO-WULF
Expert Cheater
Reputation: 0

Joined: 27 Jan 2008
Posts: 138
Location: Green Bay, Wisconsin

PostPosted: Sat Feb 02, 2008 2:01 am    Post subject: Reply with quote

Losplagos wrote:
Code:
#include "Rev0"
using std::cout;
using std::cin;
using std::endl;
using losBasicI::inpute;
using losBasicI::input;
using losBasicI::inputmm;
using losBasicMath::losRound;
double add (double x, double y);
double mult(double x,double y);
double deduct(double x,double y);
double divide(double x ,double y);

int main()
{
  double x = 0.0, y = 0.0;
  int choose = 0;
  bool loop = true;
  while(loop == true)
  {
  cout << "0:Quit" << endl << "1:adding" << endl << "2:deducting" << endl << "3:multiplying" << "\n" << "4:dividing"<< endl << "Please make your choice: " ;
  choose = inputmm(0,5);
  switch(choose)
  {
  case 0:
  cout << "Good bye" << endl;
  loop = false;
  break;
         
  case 1:
  cout<<"Please input the first number to be added: ";
  x = losRound<double>(input<double>(),4);
  cout << "2nd number please:" ;
  y =losRound<double>(input<double>(),4);
  cout<< x << "+" << y << "=" << losRound<double>(add ( x, y ),4) << endl;
  break;
  case 2:
     cout << "Please input the first number to be deducted: ";
     x = losRound<double>(input<double>(),4);
     cout << "2nd number please: " ;
     y = losRound<double>(input<double>(),4);
     cout << x << "-" << y  <<"=" << deduct(x , y) << "\n" ;
      break;
   case 3:
     cout << "Please input the first number to be multiplied: " ;
     x = losRound<double>(input<double>(),4);
     cout << "2nd number please: " ;
      y = losRound<double>(input<double>(),4);    
      cout << x << " times " << y << "=" << losRound(mult(x, y), 4) << endl;
     break;
  case 4:
     cout << "Please input the first number to be divided: " ;
     x = losRound<double>(input<double>(),4);
     cout << "2nd number please: " ;
     y = losRound<double>(inpute<double>(0),4);
     cout << x << "/" << y << "=" <<  losRound(divide(x,y),4) << endl;
     break;
   }
   }
}

double add (double x,double y )
{
  return x + y;
}
double mult (double x,double y)
{
   return x*y;
}
double deduct(double x ,double y)
{
   return x-y;
}
double divide(double x,double y)
{
   return x/y;
}


Cleaned up the code a little and here is Rev0 make sure it is in the same directory as the .cpp file.

Code:

#include <iostream>
#include <math.h>
namespace losBasicI
{
          template <typename T>
          T input()
          {
          T returnvalue;
          std::cin >> returnvalue;
           while (std::cin.fail())
              {
              std::cout << "Bad input Try again: ";
              std::cin.clear(); // Clear failbit
              std::cin.sync(); // Sync the stream
              std::cin >> returnvalue; // Try again
              }
           return returnvalue;
           }
         
          template <typename T>
          T inputmm(T min, T max) //Always use this before a switch No execeptions
          {
          T returnvalue;
          std::cin >> returnvalue;
           while(std::cin.fail()||returnvalue < min||returnvalue > max)
              {
              std::cout << "Bad input Try again: ";
              std::cin.clear(); // Clear failbit
              std::cin.sync(); // Sync the stream
              std::cin >> returnvalue; // Try again
              }
              return returnvalue;
           }
          template <typename T>
          T inpute(T equal)
          {
          T returnvalue;
          std::cin >> returnvalue;
          while(std::cin.fail()||returnvalue == equal)
              {
              std::cout << "Bad input Try again: ";
              std::cin.clear(); // Clear failbit
              std::cin.sync(); // Sync the stream
              std::cin >> returnvalue; // Try again
              }
          return returnvalue;
          } 
} // End of namespace losbasici

namespace losBasicMath
{
          template <typename T>
          T losRound(T num, int decimalplaces)
          {
                       switch(decimalplaces)
                       {
                       case 1:
                            num = floor(num*10)/10;
                            break;
                       case 2:
                            num = floor(num*100)/100;
                            break;
                       case 3:
                            num = floor(num*1000)/1000;
                            break;
                       case 4:
                            num = floor(num*10000)/10000;
                            break;
                       case 5:
                            num = floor(num*100000)/100000;
                            break;
                       case 6:
                            num = floor(num*1000000)/1000000;
                       }
                       
                       return num;
           }                                   
}


If you need help with Rev0 feel free to ask it is just for rounding and checking your input.


--------------------------------------------------------------------------------
its the dll code .exe its been broken up into 3 main sequinces and [Q!=0] is reproduced version of the numerical number that does not equal to the right number thats why it crashed is becuase it cant equal to its self only to the last partal code.
---------------------------------------------------------------------------------

_________________


4 L1F3 ( + [__] : : ) 4 L1F3
Back to top
View user's profile Send private message Yahoo Messenger
NuclearPowered
Master Cheater
Reputation: 0

Joined: 30 Dec 2007
Posts: 345

PostPosted: Tue Feb 05, 2008 3:22 pm    Post subject: Reply with quote

Lol it exits when you fill in a number like 54 at the menu...

mine is better

(use dev C++ to access the whole project)



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites