This is the void function that I am using to get these ratio's.
Expand|Select|Wrap|Line Numbers
- void CommentEvaluation(/* in */ string codeArray[], int size, ofstream& dataOut)
- //This function computes the ratio of total lines of code
- //to the number of comment lines, and ratio of total number
- //of non comment and non blank lines to the total
- //number of code.
- //Preconditions:codeArray is defined and has values
- //Postconditions: output is sent to file
- {
- int counter=0;
- int arrayNumber=0;
- char firstChar;
- int commentTotal=0;
- int lineTotal=0;
- int codeTotal=0;
- float commentRatio;
- float codeRatio;
- while (counter != size)
- {
- codeArray[arrayNumber]=firstChar;
- if (firstChar = "/")
- {
- commentTotal++;
- lineTotal++;
- }
- else
- {
- lineTotal++;
- if (firstChar != " ")
- codeTotal++;
- }
- counter++;
- }
- commentRatio= commentTotal/lineTotal;
- codeRatio= codeTotal/lineTotal;
- dataOut << "Ratio of total number of comment lines to the total number of source code lines: " << commentRatio;
- dataOut << "Ratio of total number of non-comment lines and non-blank lines to the total number of source code lines in file. " << codeRatio;
- }
The error report is :
1>c:\documents and settings\matt\m y documents\visua l studio 2008\projects\a ssign4\assign4\ assign4.cpp(56) : error C2440: '=' : cannot convert from 'const char [2]' to 'char'
1> There is no context in which this conversion is possible
1>c:\documents and settings\matt\m y documents\visua l studio 2008\projects\a ssign4\assign4\ assign4.cpp(64) : error C2446: '!=' : no conversion from 'const char *' to 'int'
1> There is no context in which this conversion is possible
1>c:\documents and settings\matt\m y documents\visua l studio 2008\projects\a ssign4\assign4\ assign4.cpp(64) : error C2040: '!=' : 'int' differs in levels of indirection from 'const char [2]'
1>c:\documents and settings\matt\m y documents\visua l studio 2008\projects\a ssign4\assign4\ assign4.cpp(70) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>c:\documents and settings\matt\m y documents\visua l studio 2008\projects\a ssign4\assign4\ assign4.cpp(71) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>Build log was saved at "file://c:\Documents and Settings\Matt\M y Documents\Visua l Studio 2008\Projects\a ssign4\assign4\ Debug\BuildLog. htm"
1>assign4 - 3 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
So it seems me comparing the char value to "/" and " " is creating some errors, any idea's on how to solve this?