mitrmkar 1,056 Posting Virtuoso

If you have:

WORD * pLeft = (WORD *) pl;

then you use pLeft->count and pLeft->word
and the same way
pRight->count and pRight->word

So you can e.g. compare the words by calling:

strcmp(pLeft->word, pRight->word)

Remember that in the sort function, you only access two individual elements of your word[] array and compare just those two elements (pLeft and pRight) hence telling qsort() how to order these elements. You need/should/must not access your word[] array at all from within your sort function.

You can output the elements inside your sort function by having e.g.

printf("mySort: left argument (%d/%s) - right argument (%d/%s)\n", pLeft->count, pLeft->word, pRight->count, pRight->word);

just to see what gets into your sort function.

>> Are those temporary variables?
Yes, they are just temporary pointers providing access to the actual data.
Maybe names like LeftElemPtr and RightElemPtr would be more descriptive.

mitrmkar 1,056 Posting Virtuoso

I'd rather use something like

if(MAXWORDS == wcount)
{
printf("Error: maximum number of words (%d) already used. Aborting ...\n", MAXWORDS);
exit(1);
}

In general, whenever your programs fail/exit due to some error condition, try to be informative, so that the user gets some insight on what went wrong (they may be able do something to remedy the situation and retry).

mitrmkar 1,056 Posting Virtuoso

Just remembered that I did not answer your question:

"Regarding the checking if the wcount is still less than the MAXWORDS, what output should I make if ever the wcount is still right or vice versa?"

There is no sense in continuing the program if the upper limit has been reached (because there are no means to dynamically grow the word[] array).
So, maybe just output a descriptive error message in that case and exit the program. You can use the exit() function for that purpose.

mitrmkar 1,056 Posting Virtuoso

First of all, your sort function (you need only one of them actually), has to be declared as

int mySort(const void * pl, const void * pr)

otherwise it will not compile/work.

The qsort() calls your sort function (which is the brains of the sort) as many times as it deems to be necessary to have your word[] array fully sorted.
You don't have to care about how many times that is, just focus on the fact, that every time your sort function is called (by qsort()), you effectively receive two pointers to a structure of type WORD (the left-hand side and the right-hand-side).

Now, if the left-hand side should be ordered before the right-hand side, return a negative value,
else, if it is vice versa, return a positive value else return zero (i.e. the elements are equal, having same freq count and the strings being equal too). Notice that the semantics of the return value is the same as with strcmp(), which you can use in your sort function.

So, in your one and only sort function, first compare the frequency, if that's equal, let strcmp() do the comparison, else figure out whether to return positive or negative value.

This is the basic construct of your sort function

int mySort(const void * pl, const void * pr)
{
     // Get the pointers to the two WORD structs and compare
     WORD * pLeft = (WORD *) pl;
     WORD * pRight = (WORD …
mitrmkar 1,056 Posting Virtuoso

<< in what order this qsort sorts a certain list?
You don't actually have to think about it, leave it as an internal of qsort().
Just be sure that your own sort function works as planned and provide valid arguments to the qsort() call.

Maybe I didn't understand you right ... so the final order of the elements in your array after qsort(), is practically dictated by your own sort function.

mitrmkar 1,056 Posting Virtuoso

Well it is getting closer ... but there are errors, I try to explain.

void Insert(char *token)
{
        int i, loop;

        // Array indexes are zero-based, hence you start from 0, 
        // and loop must be less than wcount, so ...
        for(loop = 0; loop < wcount; loop++)
        {
                i = strcmp(token, word[loop].word);
                if( i == 0 ) {
                        word[loop].count++;
                        return;  // This is perfectly OK
                }
                else{
                // This else part was completely wrong ...
                // Just think about it, if token is not at index pointed 
                // to by 'loop', it may very well be at the next index or 
                // somewhere after that ...
                // so, you have to go through all the existing entries you
                //  currently have, i.e. you must do nothing within this else 
                // block here. 
                }
        }

        // So, we are out of the loop here ...
        // Now that you've looped the whole table without finding a match, you
        // insert a new entry 

        word[wcount].word = token;
        cgiHtmlEscape(word[wcount].word);
        fprintf(cgiOut, " , ");
        // word[wcount].count is a number, so you do not need to/
        // cannot HTML-escape it
        // cgiHtmlEscape(word[wcount].count);
        // you can write it to file as follows, if you want to
        fprintf(cgiOut, "%d", word[wcount].count);

        wcount++;
}
mitrmkar 1,056 Posting Virtuoso

Sorry to say, but no. The loop should be like;

void Insert(char *token)
{

for(i = 0; i < Count_Of_Words_Inserted_To_Table; i++)
{
     // This comparison is OK
     n = CompareStr(token, word[i].word);
     if(n == 0)
     {
           // This is also OK, increment the count
           word[i].count++;
           // but RETURN STRAIGHT AWAY ... 
           [B]return;[/B]
        }
}

// Now, because we are here, it means one thing only,
// which is that the token was not found in the table.
// (we looped the whole table through)
// So, just insert the token to the table

word[Count_Of_Words_Inserted_To_Table].word = token;

// and keep track of the count of words in the table
Count_Of_Words_Inserted_To_Table = Count_Of_Words_Inserted_To_Table + 1;
}

I take that the variable 'int loop' originates from your Parse() function, please drop that variable altogether - you do not need it and must not use it in Insert().
Count_Of_Words_Inserted_To_Table is equal to the WordCount variable I've used in the previous postings. (I.e. a global variable accompanying your word[] array.)

And remember to check that Count_Of_Words_Inserted_To_Table will not exceed the size of your word[] array! If it does, you will be enjoying a program crash.

mitrmkar 1,056 Posting Virtuoso

Oh mine, you still have a local variable WORD word inside the function ... that just won't work.
void Insert(char *token, int loop)
{
int i, n;
WORD word;
}

You must have an array of WORD structures declared outside your functions. i.e.

#include <stdio.h>
#include <string.h>
#define MAX_WORDS 1000
WORD word[MAX_WORDS] = {0}; // The one and only WORD table that you declare and use
unsigned WordCount = 0;
int main(int argc, char * argv[])
{
     // the program code here ...
}

You can also replace the CompareStr() function with strcmp().
Based on the previous postings, I'd say that your input string (which you parse) IS terminated with a NULL character, so don't worry about that.

mitrmkar 1,056 Posting Virtuoso

One more question about this: What does the 'buffer++' do? If I apply this function, will it directly convert each word to lowercase? Thanks.

buffer++ increments the pointer (i.e. buffer) to point to the next character.

The condition "while(*buffer)" could be written as
while('\0' != *buffer)
i.e. loop until you encounter the terminating NULL character in the string.
(If the string is NOT terminated with a NULL character, then the loop is good at producing a nice program crash sooner or later.)

It directly converts each character to lowercase.

mitrmkar 1,056 Posting Virtuoso

Meaning, I have to place some more codes/incorporate some more functions in order to make sure that no similar words might have a double assignment. Am I getting it right?

Yes, there are two todo:s in the above Insert() function, which you have to do.
The check for exceeding the maximum number of words used in that function is also essential.

mitrmkar 1,056 Posting Virtuoso
void Insert(char *token, int loop)
{
        // This won't work at all <=> a single, non-static 
        // local WORD structure !!!
        [B]WORD word;[/B]
        word[loop].word = token;
        cgiHtmlEscape(word[loop].word);
}

Please take a closer look at my previous post.
Notice that you only want to insert a word which does not pre-exist in the table.
This implies that you have to search the existing entries and operate on the basis of that search.

mitrmkar 1,056 Posting Virtuoso

And correct me if I'm wrong, as far as I know strings cannot be taken as separate characters to be manipulated by any command in the ctype.h library [where tolower is].

You can write yourself a routine that converts the input to lower case character by character, e.g. like;

void strlower(char * buffer)
{
	while(*buffer)
	{
		*buffer = tolower(*buffer);
		buffer ++;
	}
}

About the Parse() function, it seems to be OK. I take that the cgiHtmlEscape(token) does not modify the input buffer, so using it is OK, too. (Based on what I found in http://www.koders.com/c/fid273B6AAF9CA572AEAC4D91193A4ED0052119532E.aspx?s=cgiHtmlEscape#L2465)

But when it comes to the words table + the Insert() function, there you are going wrong.

#define MAXWORDS 100
size_t nWordsUsed[B] = 0[/B]; // Initialize to zero!
// I would change the typedef to ...
typedef struct
{
   char *word;
    int wfreq;
} WORD;
// Then ... the table that you will be using ([B]outside any functions[/B]),
// also zero-initialized.
WORD table[MAXWORDS] = {0};

void Insert (char *token)
{
    // We have a valid token here, which may or may not be already in table,
    // loop through the existing entries, if any, and check whether to insert or
    // increment the freq count
    for(unsigned nn = 0; nn < nWordsUsed; nn ++)
    {
       // assuming token is in lower case
       if(0 == strcmp(token, table[nn].word))
       {
            // todo: increment the freq count and [B]return[/B] ...
       }
    }

     // no match, a new word into the table ...

     // …
mitrmkar 1,056 Posting Virtuoso

I'll get back to this in 15 mins or so ...

mitrmkar 1,056 Posting Virtuoso

>> ... the result is a single string.
I suppose you are able to modify that 'single string'? If so, you should be able to apply tolower() to the whole string before parsing anything (I'm not familiar with cgi lib (sorry)).

>> Then I was able to parse it into words [which are also strings]
=> good.
So I take that you effectively modify the input string by replacing non-alphas with a '\0' character when you parse (?).
Note! When you iterate over the string parsing it, be sure not to go past the input string (I take that it is a C-style string, i.e. terminated by a '\0' character).

It might prove very helpful if you post the code which is doing the word insertions to the table.
Showing also how you have actually declared the table.

mitrmkar 1,056 Posting Virtuoso

The parsed tokens are in string form,is there any way that I could manipulate them as arrays? I'm referring to the comparing of each character so I can do things like : making them all in lowercase,

If you read the whole input into one block of dynamically allocated memory, regarding lower case conversion, do it before you parse anything by applying tolower() on the whole input you have. So, you do not have to worry about character case after that anymore.

comparing them with each other, etc.

If you store the pointers to a table of the Entry structs, you can iterate over the table and compare the individual entries you have stored e.g.

for(unsigned nn = 0; nn < nWordsUsed; ++ nn)
{
   if(0 == strcmp(table[nn]._pWord, someString))
   {
        // someString is already in the table
        ....
   }
}

Probably that was what you were wondering about (I hope).
Another place you need to use strcmp(), is your sort function (assuming that you will use qsort()).

mitrmkar 1,056 Posting Virtuoso

>> can you give me a tip regarding memory allocations during the parsing part?
I would suggest that you read the input from the file in one fread() function call. I.e. read the file in at once - for that you have to dynamically allocate enough memory.
After you have allocated the needed memory, you do not have to use any memory allocation after that. This can be achieved if
a) your Parse() function modifies the input buffer by replacing non-alpha's with a null character
b) your Insert() function just sets the word pointer to point to the allocated memory. So you don't need to do anything like "Entry._pWord = (char*)malloc(...)", instead just set the _pWord to point to the word in the input buffer.

Trying to make this a bit clearer .. say that you have a non-constant string
char MyInputData[] = "This is a test string";
No you parse the whole string,
Parse(MyInputData)
which renders the string to:
"This0is0a0test0string"
i.e. 0==NULL character. The Entry table would contain 5 entries pointing to the MyInputData string, e.g. table[0]._pWord == MyInputData and table[1]._pWord == &MyInputData[5] etc.
Finally, when you are done, remember to free() the memory you have allocated.

mitrmkar 1,056 Posting Virtuoso

did the grandtotal, but if I change the %ds to %lf then it adds decimal places to the quantity. What if I change the whole ticketquan part to an integer instead? Would there be a way for me to convert the integer to a double so I can multiply it with the price?

ticketquan surely can be an integer (and is more natural in that way), so the answer is yes.

mitrmkar 1,056 Posting Virtuoso

Here is the version I used (and please go through the %d's and change to %lf where-ever you output a double using printf())

void heading(void);
void quanerror(double min);
void costerror(double min);
double getfloat(char prompt[], double min);
double getdouble(char prompt[], double min);
double total(double ticketquan, double ticketcost);
void show(double ticketquan, double ticketcost, double tickettotal, double grandtotal);
int contyn(char msg[]);

int main()
{
	double quanmin, ticketquan, ticketcost, tickettotal, costmin, grandtotal;
	char choice;
	quanmin = 0;
	costmin = 5;
	[B]grandtotal = 0;[/B]

	do
	{
	heading();
	ticketquan = getdouble("quantity", quanmin);
	ticketcost = getfloat("price", costmin);
	tickettotal= total(ticketquan, ticketcost);
	grandtotal+= tickettotal;
[B]	show(ticketquan, ticketcost, tickettotal, grandtotal);
	choice  = contyn("\nWould you like to purchase more raffle tickets?");	
[/B]	}
	while (choice == 'y' || choice == 'Y');

        return 0;
}
/* ================================================================ */

void heading()
{
	system("cls");  // Linux/Unix use: system("clear");
	printf("WELCOME TO THE RAFFLE!\n");
	return;
}
/* ================================================================ */
double getdouble(char item[], double min)
{
   int err;
   double ticketquan;
   min = 0;
   do
   {
   printf("\nEnter a ticket %s greater than or equal to [B]%lf[/B]: ", item, min);
   //scanf("%d%*c", &ticketquan);
   scanf("%lf%*c", &ticketquan);
   err = (ticketquan < min);
   if (err) quanerror(min);
   }
   while (err);
   return (ticketquan);
}
/* ================================================================ */
double getfloat(char item[], double min)
{
   int err;
   double ticketcost;
   min = 5;

   do
   {
   printf("\nEnter a ticket %s greater than or equal to %.2lf: ", item, min);
   scanf("%lf%*c", &ticketcost);
   err = (ticketcost < min);
   if (err) quanerror(min);
   }
   while (err);
   return (ticketcost);
}
/* ================================================================ */
void quanerror(double min)
{
	printf("\nOut of range.  Enter a quantity …
mitrmkar 1,056 Posting Virtuoso

I tested it with a couple of modifications, got the following output:

Enter a ticket quantity greater than or equal to 0: 5
Enter a ticket price greater than or equal to 5.00: 8

Amount of tickets: 5.000000
Price per ticket : 8.00
Total amount due : 40.00
Grand total of all purchases: 40.00

...

#1 in the main() function, initialize "grandtotal=0"
#2 Switch order of the two lines to be like below
show(ticketquan, ticketcost, tickettotal, grandtotal);
choice = contyn("\nWould you like to purchase more raffle tickets?");

mitrmkar 1,056 Posting Virtuoso

Fix the flawed scanf_s() call to be like below:

double getdouble(char item[], double min)
{
...
printf("\nEnter a ticket %s greater than or equal to %d: ", item, min);
scanf_s("%[B]lf[/B]%*c", &ticketquan);
...

Some calls to printf() are erroneous in the same way, i.e. you use %d to output a value of type double.

mitrmkar 1,056 Posting Virtuoso

Just to give some basic ideas, you might do with the following simple setup, without linked lists involved at all.
Use a structure like e.g.

typedef struct 
{
    const char * _pWord; // pointer to the word
    unsigned int _nFreq;  // its frequency
}Entry;

To make it easy, have a fixed size table of Entry structs e.g.

#define MAX_WORDS 123
Entry table[MAX_WORDS] = {0};

and track the amount of used entries by e.g.

size_t nWordsUsed; // Increment when a word is inserted to the table

Write a function that parses the input i.e. splits the string to words, e.g.

void  Parse(char * pWords)

Write a function that handles inserting a word into your table (called by Parse()).

void Insert(const char * pWord)

Finally, use qsort() for sorting the table, you need to write a sort function of your own to supply to the qsort(), e.g.

int mySort(const void * pl, const void * pr)
{
     // Get the pointers to the Entry structs and compare
     Entry * pLeft = (Entry *) pl;
     Entry * pRight = (Entry *) pr;
     // compare ...
     // int result = ...
     return result;
}

In your sort function, first compare the frequency, if that's equal, let strcmpi() do the comparison. For more information on qsort() http://www.cplusplus.com/reference/clibrary/cstdlib/qsort.html
So your main function could look like ...

// global variables .. (here only for simplicity's sake)
Entry table[MAX_WORDS] = {0};
size_t nWordsUsed = 0;
int main(int …
VernonDozier commented: Thoughtful post +1
mitrmkar 1,056 Posting Virtuoso

Could it be that comboBox2->SelectedItem is a NULL reference? Calling Box1->push_back() like you do is OK.

mitrmkar 1,056 Posting Virtuoso

After a ver quick look into the code, at least insideTriangle() uses uninitialized variables.

insideTriangle (double base, double height, double p_x, double p_y, double p_find_x, double p_find_y)
{
  double aX, bX, cY, centerY;
  aX = base - p_x;
  centerY = [B]cY[/B] - height; 
  if (p_find_x <= [B]bX[/B] && p_find_x >= aX)
mitrmkar 1,056 Posting Virtuoso

You have to change the initialization of numbers

long count = 0; //counts the number of numbers in the input file
  long items = 0;
  long numbers[count];
mitrmkar 1,056 Posting Virtuoso

Remove the & operator, tempString as such must be used in that scanf (tempString is a pointer, hence no need for &).

scanf("%s", [B]&[/B]tempString);

Then allocate memory before copying.

temp->artist = (char*) malloc(strlen(tempString)+1);
strcpy(temp->artist, tempString);

You may want to check that malloc() actually succeeded, (i.e NULL != temp->artist). Also remember to free() all the malloc'ed memory at some point.

mitrmkar 1,056 Posting Virtuoso

Should you check that the SelectedItem is not a null reference.

mitrmkar 1,056 Posting Virtuoso

To have your code in e.g. a static library, create a new win32 static library solution. Add your files to the solution and compile. Now you have a .lib that you can ship along with your header file(s) for others to use. See Visual Studio's help on how to take the .dll approach.

mitrmkar 1,056 Posting Virtuoso

The error is not in your for loop, it is perfectly OK.
You need to post some more code.

mitrmkar 1,056 Posting Virtuoso
mitrmkar 1,056 Posting Virtuoso

First of all, you have there two 'main' functions, one for a windows graphical interface application and one for a console application. You only can have one of them, not both. I think you can remove the WinMain() function altogether and use just the 'int main()'.

Actually the main function can be written like:

int main(int argc, const char * argv[])

-argc is number of the arguments that were given to the program
-argv[] is an array holding the arguments that were given to the program

Try out the following small program to see how you can use the arguments. Test it like:
myprog.exe somearg1 somearg2

#include <iostream>
int main(int argc, const char * argv[])
{
       // display all program arguments that it received via command line
	for(int nn = 0; nn < argc; nn ++)
	{      // the first one, at index 0, is actually the program itself, always
		cout << "program argument: #" << nn << ": " << argv[nn] << endl;
	}
        return 0;
}

If you make use of the arguments, you can code your application so that it is given the file to delete as an argument i.e. on command line:
mydelete.exe c:\temp\somefile.txt

Since you are obviously coding on Windows, you can use the DeleteFile() function that is built-in to Windows. It takes only one argument, namely the file path to delete.
Below is one solution ... you can modify it to suit your needs.


       
mitrmkar 1,056 Posting Virtuoso

<< mitrmkar, in the code u gave me, what's the purpose of WordCount++?
WordCount counts the words in the file, the ++ operator increments the value
of WordCount by one, it could also be written as: WordCount = WordCount + 1.

<< And also, I need to reprint the file WITH the spaces (hence inFile.get(ch) ) AND with every 5th
<< word replaced with 10 underscores.
OK. I get it.

Then one solution is to read the file character by character like you already do. And using a std::string to accumulate the non-whitespace characters (i.e. other than '\n', ' ' and punctuation (there are actually more of those, but that's not important now))
So every time you hit a '\n', ' ' or punctuation, at that time, if you have any characters accumulated, that makes a word.

<snip>
string aword;
unsigned int count = 0;

while ( inFile.get(ch) )
{
        // todo: check for a tabulator too
	if ( ispunct(ch) || ( ch == ' ') || ( ch == '\n'))
	{	
		if(aword.length())
		{
			// we have one or more characters, so that
			// makes us a word ...
			++ number;
			++ count;

			if( ! (count % 5))
			{
				// every fifth word is to be filtered out
				cout << "_____";
                                // reset the counter
				count = 0;
			}
			else
			{
                                // output the current word
				cout << aword;
			}

			// reset the word to empty
			aword.erase();
		}

		// output the separating …
mitrmkar 1,056 Posting Virtuoso

A couple of things to fix ...

int main()
{
    srand(time(NULL));
    int sizeArray = rand () % MAX;
//  at this point, sizeArray may very well be zero, 
//  probably you don't want that, so add a check against 
//  that condition ...
<snip>
}
int RationalInfo (int initialArray[][MAX], int size)
{  <snip>
    for (int j = 0; j < size; j++)
    {
        // if initialArray[i+1][j] is zero, your program will fail here, 
        // you must not divide by zero, ever
        initialArray[i+2][j] = initialArray[i][j] / initialArray[i+1][j];

        // the same thing with % operator, initialArray[i+1][j] must not 
        // be zero here
        initialArray[i+3][j] = initialArray[i][j] % initialArray[i+1][j];
    }
     return 1;
}
mitrmkar 1,056 Posting Virtuoso
float CelsiustoFahrenheit(int)
{
    //
    // This fails because you are dividing using two integers here,
    // 
    // result = ((9/5)*temperatureC)+32;
    //
    // use the following instead
    //
    result = ((9/5[B].0[/B])*temperatureC)+32;
    return result;
}

You might want to run the following snippet to see the difference

cout 
	<< "9/5 using integers is [ " << 9/5 << " ]" << endl 
	<< "9/5 using floating point is [ " << 9/5.0 << " ]" << endl;
mitrmkar 1,056 Posting Virtuoso

The errors boil down to the RationalInfo() function, even though you are not calling
it from anywhere, the compiler wants it to be OK, so fix it first or remove it if don't need it

int RationalInfo (int initialArray[][B][MAX][/B])
{
    [B]// You still need to declare the variables a and b here[/B]

    int quotient, remainder;
    float value;
    for (int i = 0; i <setArray; i++)
     {
         for (int j = 0; j < MAX; j++)
             {
                  initialArray [i+2][j] = initialArray [i][j] / initialArray [i+1][j];
                  
                  quotient = a/b [B];[/B]
                  remainder = a%b [B];[/B]
                  value = a/b [B];[/B]           
             }
     }

     [B]// You need to return something from this function[/B]
     return ???
}
mitrmkar 1,056 Posting Virtuoso

Maybe you get some ideas/clues from below, the important changes are that
the file is read in one word at a time + the use of operator %

>> i don't think std::string word is something we covered.

Hmm, you already have there a std::string, namely the 'cloze'.

...	
        string aWord;
	unsigned int WordCount = 0;

	// Read the file in word by word 
	// (a 'word' is here anything non-whitespace)

	while (inFile >> aWord)	    // While inFile succeeds in reading a word from the file
	{	
		// output the word
		cout << aWord;
		WordCount ++;
	}

	inFile.clear();			 // Move read pointer to beginning
	inFile.seekg(0L, ios::beg);

	unsigned int Count = 0;

	// re-read it again the same way as above
	while (inFile >> aWord)	    // While inFile succeeds in reading a word from the file
	{
		++ Count;

		// every 5th word is to be replaced, 
		// use the modulus operator (%) 
		if( ! (Count % 5))
		{
			 // replace it here

			// reset counter ...
			Count = 0;
		}
		else
		{
			// don't replace
		}    
	}

return 0 ; 
}
mitrmkar 1,056 Posting Virtuoso

Thank you so much everyone for the help. There is still one persisting problem though...if you let c3 be a high color like A or W which are worth 8 and 9 respectively, the result is -2147483648. It works for everything else, just not when the last color is a high number.

Change the code so that it works with the 'double' type instead of 'int'. A double should be able to represent the maximum value that the program produces.
I.e. change the stuff that is in bold below ...

[B]double[/B] calcRval(int,int,int);
[B]double[/B] colCode(char);

[B]double[/B] calcRval(int c1,int c2, int c3)
{
    [B]double[/B] v1,v2,v3,v;
    ...
-------------------------------------------------

[B]double[/B] colCode(char colCode)
{
    ...
-------------------------------------------------
and in the main() function ...

    [B]double[/B] val = calcRval(c1, c2, c3);
    // set the precision for output
    [B]cout.precision(14);[/B]
    cout << "Value = " << val << endl;
mitrmkar 1,056 Posting Virtuoso

Hi,

I quickly changed the code so that it should do what you intented.

#include <iostream>
#include <cmath>
using namespace std;

int calcRval(int,int,int);

// the input to colCode() is now a char
int colCode(char);

// these variables are not needed
// int c1,c2,c3,val;

int main()
{
        char c1,c2,c3;

	cout<<"input c1:";cin>>c1;
	cout<<"input c2:";cin>>c2;
	cout<<"input c3:";cin>>c3;

	int val=calcRval(c1,c2,c3);

        //  the signature "int main()" implies that we 
        // should return an int, so let's do so

        return val;
}

int calcRval(int c1,int c2, int c3)
{
        int v1,v2,v3,v;

	v1=colCode(c1);
	v2=colCode(c2);
	v3=colCode(c3);

        // note, that there is no validation against invalid input,
        // i.e. v1 .. v3 may very well be -1 here ...

	v=((10*v1+v2)*pow(10,v3));

        return v;

} // Here ends the calcRval function

int colCode(char colCode) 
{
        // map the color code letter to a value

        switch(colCode)
        {
		case 'B': return 0;
		case 'N': return 1;
		case 'R': return 2;
		case 'O': return 3;
		case 'Y': return 4;
		case 'G': return 5;
		case 'E': return 6;
		case 'V' :return 7;
		case 'A': return 8;
		case 'W': return 9;
                default:
                // invalid color
                break;
	}  // Here ends the switch

       cerr << "Ooops, invalid color code: " << colCode << endl;

       // This means invalid color
       return -1;

}  // Here ends the colCode function