|
|
|
please help (VC++)
|
Original Message
|
Name: Tugg
Date: February 13, 2003 at 19:18:26 Pacific
Subject: please help (VC++)OS: Win98\WinXPCPU/Ram: 800MHz\256SDRam |
Comment: I have posted a poblem here before but unfortunatly no one could or wanted to help me so I guess I'll try again. This IS NOT A HOMEWORK ASSIGNMENT (i am teaching myself VC++ from what I already know from Java): I am working on a small currency conversion program and am stuck on an array sub -routine. I want the sub-routine to take the user's input of a currency code like USD and compare it to the values of this array: char currency[][20] = {{"USD","HKD","TB"}{"USD","HKD","TB"}}; After that the routine has to pass the row/column value to the exchange rate array to get the exchange rate: double conversion[][20] = {{1,5,42.86}{1,5,42.86}}; I am NOT asking anyone to supply the finished code to me, but to give me an idea of how to write a function that does what I just described. After all I want to learn something. So please help if you can. Thanks!
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: Ronin1
Date: February 13, 2003 at 21:29:20 Pacific
Subject: please help (VC++)
|
Reply: (edit)char currency[] = { "USD", "HKD" ... }; get user's code convert the user's entry to uppercase use a loop and strcmp to compare the user's entry and one of your codes if true do conversions if false do some action There's an uppercase function in the string class that you can use if you use a string instead of a character array. If you use the character array, then you need to use toupper and manually convert each character of the array. loop if(strcmp(user string, currency[index]) == 0) string matched one of your codes. do conversion end loop The same thing with the conversions. Use the user's code and compute your exchange rate from the arrays. double convert[] = { num1, num2,... };
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: Tugg
Date: February 13, 2003 at 21:46:30 Pacific
Subject: please help (VC++) |
Reply: (edit)Thanks. I didn't there was something like strcmp. I'll try using a string array now. Thanks again.
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: Mathew Joy
Date: February 13, 2003 at 22:03:32 Pacific
Subject: please help (VC++)
|
Reply: (edit)Dear Tugg, I think nobody helped cause it is simple enough. I guess u know how to write a loop to traverse a 2 dimentional array. The outer loop for the row and the inner for the col. U can use stricmp() function to compare with ignore case. Once a match is found use 'break' statement to break out of the loop(u can use [bool variable] flag to break out of both loops). Once u are out of the loop store the value of row and col and use it to retrive the exchange rate from the other array. One point to note is that u also have to find if there is a match at all. I leave that to u. Think and u'll get.
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: Ronin1
Date: February 14, 2003 at 11:00:49 Pacific
Subject: please help (VC++)
|
Reply: (edit)I forgot about stricmp, but don't forgot to include string.h or you might be a little miffed at compile time. :)
Report Offensive Follow Up For Removal
|
|
Response Number 5
|
Name: Tugg
Date: February 18, 2003 at 22:43:36 Pacific
Subject: please help (VC++) |
Reply: (edit)ok. First of all thanks alot for everything, I did advance alot with the program. Now I know I said i did not want to be handed any code, but it looks like I will need a coded sample of something similar to what I explained above because I just cant figure out the proper syntax for the look-up routine (tried ever since the first reply). So in other words: please give me some sample code (from anything) using strcmp with an array. Thanks alot again.
Report Offensive Follow Up For Removal
|
|
Response Number 6
|
Name: Mathew Joy
Date: February 19, 2003 at 00:41:50 Pacific
Subject: please help (VC++)
|
Reply: (edit)dear Tugg, Once u've included string.h then u can use the strcmp or the stricmp. The syntax for both is the same. int strcmp(const char *string1,const char *string2 ); It returns an integer value. The int value - less than 0 - string1 less than string2 0 - string1 identical to string2 greater than 0 - string1 greater than string2 eg: char str1[50], str2[50]; ....... get the values if(stricmp(str1,str2)==0) // the strings are equal NB: if u are familiar with pointers do so. if ur using visual studio u may have to prefix a '_' before stricmp. Install an msdn to get help on syntax.
Report Offensive Follow Up For Removal
|
|
Response Number 7
|
Name: Tugg
Date: February 19, 2003 at 17:41:40 Pacific
Subject: please help (VC++) |
Reply: (edit)Dear Matthew Joy, The example helped me out enough to get this part almost done, so thanks (although I dont yet know about pointers. This will be the next thing on my to-learn list). Now maybe its just me, but all the MSDN's I found are for Visual Basic 6.0 But I am using Visual C++ 6.0; will the msdn and "Code Advisor" still work under that program?
Report Offensive Follow Up For Removal
|
|
Response Number 8
|
Name: Mathew Joy
Date: February 19, 2003 at 23:29:51 Pacific
Subject: please help (VC++)
|
Reply: (edit)Dear Tugg, Learning programming by oneself is the best way to become a good programmer. The more u use trial and error method the better. About the question asked, there is no msdn just for vb. MSDN is ment for developers working in microsoft's visual programming IDE such as VC,VB,VJ++,Vfoxpro etc. Ur problem might be either selecting the wrong subset or installing just the VB collection. Check if the Active Subset in msdn(top left)is selected to either 'entire collection' or 'vc++,sdk, enterprize docs' are selected. By selecting the latter u can make sure that only the keywords of VC is enabled. If ur still having problem then u've not installed properly. While installing either select the full installation option or choose customize and check all the enteries. Note that MSDN comes in 3 CDs.
Report Offensive Follow Up For Removal
|

|

|
Use following form to reply to current message:
|
|

|