simondid

calculator

Oct 27th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.74 KB | None | 0 0
  1.  
  2. #include <iostream>
  3.  
  4.  
  5.  
  6. using namespace std;
  7. void behandelLigning(char input[]);
  8. char ligning[100];
  9.  
  10. float tempA=0;
  11. float tempAA=0;
  12. float tempC=0;
  13. float tempB=0;
  14. float a = 0;
  15. float b = 0;
  16. float c = 0;
  17. float final;
  18. int main(int argc, const char * argv[])
  19. {
  20.    
  21.    
  22.    
  23.     cout << "velkommen til lommeregneren :)"<<endl;
  24.     cin >> ligning;
  25.     behandelLigning(ligning);
  26.    
  27.    
  28.    
  29.     return 0;
  30. }
  31. void behandelLigning(char input[]){
  32.    
  33.     for (int i =0; i<100; i++) {
  34.        
  35.         if (input[i]=='x') {
  36.             tempAA=input[i-1]-48;
  37.             if (input[i-2]=='-') {
  38.                
  39.                 // b=b*-1;
  40.                 tempAA=tempAA*-1;
  41.             }else if (input[i-2]=='+'){
  42.                
  43.                 tempAA=tempAA*tempAA/tempAA;
  44.             }
  45.             cout << " tempAA før = ="<<tempAA<<" x"<<endl;
  46.  
  47.             tempA=tempA+tempAA;
  48.            
  49.         }
  50.        
  51.         if (isdigit(input[i])) {
  52.             if(input[i+1]=='x'){
  53.                 // gør ingen ting da det er en x værdi
  54.             }else{
  55.                
  56.                 if (b==48) {
  57.                     tempB=input[i]-48;
  58.                 }else{
  59.                     tempB=input[i]-48;
  60.                 }
  61.                
  62.                
  63.                 if (input[i-1]=='-') {
  64.                    
  65.                     // b=b*-1;
  66.                    
  67.                     tempB=tempB*-1;
  68.                 }else if (input[i-1]=='+'){
  69.                 }
  70.                
  71.                 cout << "tempB før = ="<<tempB<<endl;
  72.                 b=b+tempB*-1;
  73.             }
  74.         }
  75.        
  76.         //^^^^ før ligheds tegnet under efter ligheds tegnet
  77.        
  78.         if (input[i]=='=') {
  79.             for (int re =0; i<100; i++) {
  80.                 if (input[i]=='x') {
  81.                     tempAA=input[i-1]-48;
  82.                     if (input[i-2]=='-') {
  83.                        
  84.                         // b=b*-1;
  85.                         tempAA=tempAA*-1;
  86.                     }else if (input[i-2]=='+'){
  87.                        
  88.                         tempAA=tempAA*tempAA/tempAA;
  89.                     }
  90.                     cout << " tempAA efter = ="<<tempAA<<" x"<<endl;
  91.                     tempA=tempA+tempAA*-1;
  92.                    
  93.                 }
  94.                
  95.                 if (isdigit(input[i])) {
  96.                     if(input[i+1]=='x'){
  97.                         // gør ingen ting da det er en x værdi
  98.                     }else{
  99.                        
  100.                         if (c==48) {
  101.                             tempC=input[i]-48;
  102.                         }else{
  103.                             tempC=input[i]-48;
  104.                         }
  105.                        
  106.                        
  107.                         if (input[i-1]=='-') {
  108.                            
  109.                             // b=b*-1;
  110.                            
  111.                             tempC=tempC*-1;
  112.                         }else if (input[i-1]=='+'){
  113.                             // gør ingen ting da det er +
  114.                         }
  115.                        
  116.                         cout << "tempC efter = ="<<tempC<<endl;
  117.                         c=c+tempC;
  118.                     }
  119.                 }
  120.                
  121.             }
  122.            
  123.            
  124.            
  125.            
  126.         }
  127.        
  128.        
  129.     }
  130.     a=tempA;
  131.     // a=tempA+tempAA;
  132.     cout <<endl;
  133.     cout<<"tempA="<<tempA<<endl;
  134.     cout<<"tempAA="<<tempAA<<endl;
  135.    
  136.     cout<<"a="<<a<<endl;
  137.     cout<<"b="<<b<<endl;
  138.     cout<<"c="<<c<<endl;
  139.     if (c==48) {
  140.         final=b+(c-48);
  141.     }else{
  142.         final = b+c;
  143.     }
  144.    
  145.    
  146.     cout<<"fianl b+c = "<<final<<endl;
  147.    
  148.     cout<<"x="<<final/a;
  149.    
  150. }
Advertisement
Add Comment
Please, Sign In to add comment