mzawieska Posted February 16, 2009 Share Posted February 16, 2009 I am havin problems with this compiler..i really Like geany but I am gettin errors. This program runs on DEvcpp compiler on my windows but on geany I am gettin errors can u guys help me this is my program #include<iostream> #include<fstream> #include<string> #include<iomanip> #include<cmath> using namespace std; struct MATRIX { double a11, a12,a21, a22; }; void file_open(ofstream &Out); int file_close(ofstream &Out); void print_matrix(MATRIX m, char word[], ofstream &out); void get_matrix(MATRIX &matrix, char name[]); void get_scalar(double &k); void calc_sum(MATRIX m1, MATRIX m2, MATRIX ∑); void calc_diff(MATRIX m1, MATRIX m2, MATRIX &diff); void scalar_mult(double k, MATRIX m, MATRIX &km); void calc_prod (MATRIX m1, MATRIX m2, MATRIX ∏); void calc_inverse(MATRIX m, MATRIX &inverse); int main() { MATRIX matrix1, matrix2, sum, difference, product,inverse, sMult; double k=4.5; char name1[20], name2[20]; ofstream outfile; file_open(outfile); get_matrix(matrix1, name1); get_matrix(matrix2, name2); get_scalar(k); calc_sum(matrix1, matrix2, sum); calc_diff(matrix1,matrix2,difference); scalar_mult (k, matrix1, sMult); calc_prod(matrix1, matrix2, product); calc_inverse(matrix1, inverse); print_matrix(matrix1, name1,outfile); print_matrix(matrix2, name2,outfile); print_matrix(sum, "Sum =", outfile); print_matrix(difference, "Difference = ", outfile); print_matrix(sMult, "Scalar Product = ", outfile); print_matrix(product, "Matrix Product = ", outfile); print_matrix(inverse, "Inverse = ", outfile); file_close(outfile); return 0; } void get_matrix(MATRIX &matrix, char name[]) { cout<<"Enter the name of the Matrix :"; cin>>ws; cin.getline(name,20); cout<<"Enter m1: "; cin>>matrix.a11; cout<<"Enter m2: "; cin>>matrix.a12; cout << "Enter m3: "; cin >> matrix.a21; cout<<"Enter m4: "; cin>>matrix.a22; } void get_scalar(double &k) { cout<<endl<<"Enter scalar value: "; cin>>k; } void calc_sum(MATRIX m1, MATRIX m2, MATRIX ∑) { sum.a11 = m1.a11 + m2.a11; sum.a12 = m1.a12 + m2.a12; sum.a21 = m1.a21 + m2.a21; sum.a22 = m1.a22 + m2.a22; } void calc_diff(MATRIX m1, MATRIX m2, MATRIX &diff) { diff.a11 = m1.a11 - m2.a11; diff.a12 = m1.a12 - m2.a12; diff.a21 = m1.a21 - m2.a21; diff.a22 = m1.a22 - m2.a22; } void scalar_mult(double k, MATRIX m, MATRIX &km) { km.a11 = m.a11 * k; km.a12 = m.a12 * k; km.a21 = m.a21 * k; km.a22 = m.a11 * k; } void calc_prod (MATRIX m1, MATRIX m2, MATRIX ∏) { prod.a11= m1.a11 * m2.a11 + m1.a12 * m2.a21; prod.a12= m1.a11 * m2.a11 + m1.a12 * m2.a21; prod.a21= m1.a11 * m2.a11 + m1.a12 * m2.a21; prod.a22= m1.a11 * m2.a11 + m1.a12 * m2.a21; } void calc_inverse(MATRIX m, MATRIX &inverse) { double det = m.a11 * m.a22 - m.a21 * m.a12; inverse.a11 = m.a22/det; inverse.a12 = -(m.a12/det); inverse.a21 = -(m.a21/det); inverse.a22 = m.a11/det; } void print_matrix( MATRIX matrix, char word[], ofstream &out) { out << word << " = " << matrix.a11 << " " << matrix.a12 << "\n" << " "<< matrix.a21 << " " << matrix.a22 << "\n"; } void file_open(ofstream &Out) { int choice; char drive[3]; char disk_f[20]; char file[15]; cout<< "Output to console [1] to disk file [2]: "; cin >> choice; if(choice == 1) { Out.open("con"); } else { cout<< "Which drive would you want to save your data?"; cin >> drive; strcpy(disk_f, drive); strcat(disk_f, ":"); cout<< "Please enter result file name: "; cin >>file; strcat(disk_f, file); strcat(disk_f, ".dta"); Out.open(disk_f); } Out<<setiosflags(ios::showpoint|ios::fixed)<<setprecision(2); } int file_close(ofstream &Out) { int flag; Out.close(); cin>>flag; return 0; } the errors matrix.cpp:103:27: warning: character constant too long for its typematrix.cpp: In function ?int main()?: matrix.cpp:95: warning: deprecated conversion from string constant to ?char*? matrix.cpp:97: warning: deprecated conversion from string constant to ?char*? matrix.cpp:99: warning: deprecated conversion from string constant to ?char*? matrix.cpp:101: warning: deprecated conversion from string constant to ?char*? matrix.cpp:103: error: invalid conversion from ?int? to ?char*? matrix.cpp:103: error: initializing argument 2 of ?void print_matrix(MATRIX, char*, std::ofstream&)? matrix.cpp: In function ?void file_open(std::ofstream&)?: matrix.cpp:296: error: ?strcpy? was not declared in this scope matrix.cpp:298: error: ?strcat? was not declared in this scope by the way maybe you guys know better compilers and much easier and good :0 thanks for help Link to comment Share on other sites More sharing options...
0 Matthew S. Posted February 16, 2009 Share Posted February 16, 2009 Try using GCC :/ Link to comment Share on other sites More sharing options...
0 night_stalker_z Posted February 16, 2009 Share Posted February 16, 2009 Try using <cstring> or <string.h> instead of <string>. Link to comment Share on other sites More sharing options...
0 mzawieska Posted February 16, 2009 Author Share Posted February 16, 2009 it works but I am still gettin warning ...the program works only for input ( I type all the information) then its not outputing anyything any ideas why? Link to comment Share on other sites More sharing options...
0 Tech God Posted February 16, 2009 Share Posted February 16, 2009 Geany is just a text editor... he is using GCC whether he knows it or not. Read up on type conversions in C++. Also a few of your header files must include the ".h" extension, I know iostream doesn't need the .h but i'm positive string needs the extension and maybe some of the others. Good luck. Link to comment Share on other sites More sharing options...
0 ViZioN Posted February 16, 2009 Share Posted February 16, 2009 (edited) it works but I am still gettin warning ...the program works only for input ( I type all the information) then its not outputing anyything any ideas why? Did you look at what I said in your other thread about this? char g cin >> g You need to use cin stop the console window closing Geany is just a text editor... he is using GCC whether he knows it or not. Read up on type conversions in C++. Also a few of your header files must include the ".h" extension, I know iostream doesn't need the .h but i'm positive string needs the extension and maybe some of the others. Good luck. You're right Geany is a text editor, but as you say, also has the compatibility to compile using C and C++. I'm fairly sure that you shouldn't have the .h for string header file. String.h and cstring are for using strings in C code, not C++. I'll try and find where I read that... Edited February 16, 2009 by ViZioN Link to comment Share on other sites More sharing options...
0 mzawieska Posted February 17, 2009 Author Share Posted February 17, 2009 Yea I read up about that...i tried casting char(sum),"sum",outfile; but that still doesnt solve my problem Link to comment Share on other sites More sharing options...
0 KC Posted February 17, 2009 Share Posted February 17, 2009 strcopy & strcat is for c style strings so you would need to #include cstring http://www.cplusplus.com/reference/clibrary/cstring/ It might help if you edit your post to include some better formated code because as it is right now it's nearly IMPOSSIBLE to read. Also no matter what compiler you use if your program is coded wrong it's not going to work; there is no "easier" complier (at least there shouldn't be). Different IDE's and editers may make your life easier with syntax highlighting or code completion but they don't program for you. A lot of people prefer to use emacs or vim in linux but those two programs have steep learning curves (but eventually you need to learn at least one of them if your serious about programming). Netbeans is an okay IDE on the Linux system Gedit with syntax highlight is nice too. Link to comment Share on other sites More sharing options...
Question
mzawieska
I am havin problems with this compiler..i really Like geany but I am gettin errors. This program runs on DEvcpp compiler on my windows but on geany I am gettin errors can u guys help me this is my program
#include<iostream> #include<fstream> #include<string> #include<iomanip> #include<cmath> using namespace std; struct MATRIX { double a11, a12,a21, a22; }; void file_open(ofstream &Out); int file_close(ofstream &Out); void print_matrix(MATRIX m, char word[], ofstream &out); void get_matrix(MATRIX &matrix, char name[]); void get_scalar(double &k); void calc_sum(MATRIX m1, MATRIX m2, MATRIX ∑); void calc_diff(MATRIX m1, MATRIX m2, MATRIX &diff); void scalar_mult(double k, MATRIX m, MATRIX &km); void calc_prod (MATRIX m1, MATRIX m2, MATRIX ∏); void calc_inverse(MATRIX m, MATRIX &inverse); int main() { MATRIX matrix1, matrix2, sum, difference, product,inverse, sMult; double k=4.5; char name1[20], name2[20]; ofstream outfile; file_open(outfile); get_matrix(matrix1, name1); get_matrix(matrix2, name2); get_scalar(k); calc_sum(matrix1, matrix2, sum); calc_diff(matrix1,matrix2,difference); scalar_mult (k, matrix1, sMult); calc_prod(matrix1, matrix2, product); calc_inverse(matrix1, inverse); print_matrix(matrix1, name1,outfile); print_matrix(matrix2, name2,outfile); print_matrix(sum, "Sum =", outfile); print_matrix(difference, "Difference = ", outfile); print_matrix(sMult, "Scalar Product = ", outfile); print_matrix(product, "Matrix Product = ", outfile); print_matrix(inverse, "Inverse = ", outfile); file_close(outfile); return 0; } void get_matrix(MATRIX &matrix, char name[]) { cout<<"Enter the name of the Matrix :"; cin>>ws; cin.getline(name,20); cout<<"Enter m1: "; cin>>matrix.a11; cout<<"Enter m2: "; cin>>matrix.a12; cout << "Enter m3: "; cin >> matrix.a21; cout<<"Enter m4: "; cin>>matrix.a22; } void get_scalar(double &k) { cout<<endl<<"Enter scalar value: "; cin>>k; } void calc_sum(MATRIX m1, MATRIX m2, MATRIX ∑) { sum.a11 = m1.a11 + m2.a11; sum.a12 = m1.a12 + m2.a12; sum.a21 = m1.a21 + m2.a21; sum.a22 = m1.a22 + m2.a22; } void calc_diff(MATRIX m1, MATRIX m2, MATRIX &diff) { diff.a11 = m1.a11 - m2.a11; diff.a12 = m1.a12 - m2.a12; diff.a21 = m1.a21 - m2.a21; diff.a22 = m1.a22 - m2.a22; } void scalar_mult(double k, MATRIX m, MATRIX &km) { km.a11 = m.a11 * k; km.a12 = m.a12 * k; km.a21 = m.a21 * k; km.a22 = m.a11 * k; } void calc_prod (MATRIX m1, MATRIX m2, MATRIX ∏) { prod.a11= m1.a11 * m2.a11 + m1.a12 * m2.a21; prod.a12= m1.a11 * m2.a11 + m1.a12 * m2.a21; prod.a21= m1.a11 * m2.a11 + m1.a12 * m2.a21; prod.a22= m1.a11 * m2.a11 + m1.a12 * m2.a21; } void calc_inverse(MATRIX m, MATRIX &inverse) { double det = m.a11 * m.a22 - m.a21 * m.a12; inverse.a11 = m.a22/det; inverse.a12 = -(m.a12/det); inverse.a21 = -(m.a21/det); inverse.a22 = m.a11/det; } void print_matrix( MATRIX matrix, char word[], ofstream &out) { out << word << " = " << matrix.a11 << " " << matrix.a12 << "\n" << " "<< matrix.a21 << " " << matrix.a22 << "\n"; } void file_open(ofstream &Out) { int choice; char drive[3]; char disk_f[20]; char file[15]; cout<< "Output to console [1] to disk file [2]: "; cin >> choice; if(choice == 1) { Out.open("con"); } else { cout<< "Which drive would you want to save your data?"; cin >> drive; strcpy(disk_f, drive); strcat(disk_f, ":"); cout<< "Please enter result file name: "; cin >>file; strcat(disk_f, file); strcat(disk_f, ".dta"); Out.open(disk_f); } Out<<setiosflags(ios::showpoint|ios::fixed)<<setprecision(2); } int file_close(ofstream &Out) { int flag; Out.close(); cin>>flag; return 0; }the errors
by the way maybe you guys know better compilers and much easier and good :0
thanks for help
Link to comment
Share on other sites
7 answers to this question
Recommended Posts