Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void behandelLigning(char input[]);
- char ligning[100];
- float tempA=0;
- float tempAA=0;
- float tempC=0;
- float tempB=0;
- float a = 0;
- float b = 0;
- float c = 0;
- float final;
- int main(int argc, const char * argv[])
- {
- cout << "velkommen til lommeregneren :)"<<endl;
- cin >> ligning;
- behandelLigning(ligning);
- return 0;
- }
- void behandelLigning(char input[]){
- for (int i =0; i<100; i++) {
- if (input[i]=='x') {
- tempAA=input[i-1]-48;
- if (input[i-2]=='-') {
- // b=b*-1;
- tempAA=tempAA*-1;
- }else if (input[i-2]=='+'){
- tempAA=tempAA*tempAA/tempAA;
- }
- cout << " tempAA før = ="<<tempAA<<" x"<<endl;
- tempA=tempA+tempAA;
- }
- if (isdigit(input[i])) {
- if(input[i+1]=='x'){
- // gør ingen ting da det er en x værdi
- }else{
- if (b==48) {
- tempB=input[i]-48;
- }else{
- tempB=input[i]-48;
- }
- if (input[i-1]=='-') {
- // b=b*-1;
- tempB=tempB*-1;
- }else if (input[i-1]=='+'){
- }
- cout << "tempB før = ="<<tempB<<endl;
- b=b+tempB*-1;
- }
- }
- //^^^^ før ligheds tegnet under efter ligheds tegnet
- if (input[i]=='=') {
- for (int re =0; i<100; i++) {
- if (input[i]=='x') {
- tempAA=input[i-1]-48;
- if (input[i-2]=='-') {
- // b=b*-1;
- tempAA=tempAA*-1;
- }else if (input[i-2]=='+'){
- tempAA=tempAA*tempAA/tempAA;
- }
- cout << " tempAA efter = ="<<tempAA<<" x"<<endl;
- tempA=tempA+tempAA*-1;
- }
- if (isdigit(input[i])) {
- if(input[i+1]=='x'){
- // gør ingen ting da det er en x værdi
- }else{
- if (c==48) {
- tempC=input[i]-48;
- }else{
- tempC=input[i]-48;
- }
- if (input[i-1]=='-') {
- // b=b*-1;
- tempC=tempC*-1;
- }else if (input[i-1]=='+'){
- // gør ingen ting da det er +
- }
- cout << "tempC efter = ="<<tempC<<endl;
- c=c+tempC;
- }
- }
- }
- }
- }
- a=tempA;
- // a=tempA+tempAA;
- cout <<endl;
- cout<<"tempA="<<tempA<<endl;
- cout<<"tempAA="<<tempAA<<endl;
- cout<<"a="<<a<<endl;
- cout<<"b="<<b<<endl;
- cout<<"c="<<c<<endl;
- if (c==48) {
- final=b+(c-48);
- }else{
- final = b+c;
- }
- cout<<"fianl b+c = "<<final<<endl;
- cout<<"x="<<final/a;
- }
Advertisement
Add Comment
Please, Sign In to add comment