I did the 2d array and i can get the stuff in,but it wont add, sub, div, or mlt right and the output comes out all wrong.
Code:#include "stdafx.h" #include <fstream.h> #include <iostream.h> #include <iomanip.h> #include <afx.h> #include <cstring> #include <stdlib.h> void in(char rr); void out(char rr); void add(char rr1, char rr2, char rr3); void sub(char rr1, char rr2, char rr3); void mlt(char rr1, char rr2, char rr3); void div(char rr1, char rr2, char rr3); char vv [ ] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z'}; char buffer[36]={0}; void main(){ char tt[20][10]; int i =0, x=0, y=0, cont=1; ifstream fin("a:/TransProg.txt"); char c[2]; while(fin.read(c,1)){ if(c[0] == 10){ i++; y=0;} else{ tt[i][y] = c[0]; y++;}} y=0; CString blah =""; while (cont==1){ x=0; while(x<i){ while(tt[x][y]!=' ') blah+=tt[x][y++]; y++; if(blah== "inn"){ in(tt[x][y]);} else if(blah=="out"){ out(tt[x][y]); } else if(blah="add"){ add(tt[x][y], tt[x][y+2], tt[x][y+4]); } else if(blah=="sub"){ sub(tt[x][y], tt[x][y+2], tt[x][y+4]); } else if(blah=="mlt"){ mlt(tt[x][y], tt[x][y+2], tt[x][y+4]); } else if(blah=="div"){ div(tt[x][y], tt[x][y+2], tt[x][y+4]); } x++; y=0; blah="";} cout<<"Do you wish to do it again?(Press 1 do another)"; cin>>cont; cin.get(); cout<<endl;} } void in(char rr){ int x=0; while(rr != vv[x]&&x<36){ x++; cin>>buffer[x];} } void out(char rr) { int x = 0; while(rr != vv[x]&&x<36){ x++; cout<<vv[x]<< "'s value is "<<buffer[x]<<endl;} } void add(char rr1, char rr2, char rr3) { int x = 0; while (rr1 != vv[x]&&x<36){ x++;}int y = 0; while (rr2 != vv[y]&&x<36){ y++;}int z = 0; while (rr3 != vv[z]&&x<36){ z++; buffer[z] = buffer[x] + buffer[y]; } } void sub(char rr1, char rr2, char rr3) { int x = 0; while (rr1 != vv[x]&&x<36){ x++;}int y = 0; while (rr2 != vv[y]&&x<36){ y++;}int z = 0; while (rr3 != vv[z]&&x<36){ z++;buffer[z] = buffer[x] - buffer[y]; }} void mlt(char rr1, char rr2, char rr3) { int x = 0; while (rr1 != vv[x]&&x<36){ x++;}int y = 0; while (rr2 != vv[y]&&x<36){ y++;}int z = 0; while (rr3 != vv[z]&&x<36){ z++; buffer[z] = buffer[x] * buffer[y]; } } void div(char rr1, char rr2, char rr3){ int x = 0; while (rr1 != vv[x]&&x<36){ x++;}int y = 0; while (rr2 != vv[y]&&x<36){ y++;}int z = 0; while (rr3 != vv[z]&&x<36){ z++; buffer[z] = buffer[x] / buffer[y]; } }



LinkBack URL
About LinkBacks


