943,539 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1468
  • C++ RSS
Dec 7th, 2007
0

Variable problem..

Expand Post »
Can i know what's wrong with the below source code? can i put the variable x, y like this? How it can't work?
c++ Syntax (Toggle Plain Text)
  1. #include <Windows.h>
  2. #include <mmsystem.h>
  3. #pragma comment (lib,"winmm.lib")
  4.  
  5. int ,x,y;
  6. void CTestingDlg::OnPlay()
  7. {
  8. // TODO: Add your control notification handler code here
  9.  
  10. UpdateData(TRUE);
  11.  
  12. CString strFreq;
  13. CString strHL;
  14.  
  15. strFreq = m_strFreq;
  16. strHL = m_strHL;
  17.  
  18. strFreq.MakeUpper();
  19. strHL.MakeUpper();
  20.  
  21. if(strFreq=="x" && strHL=="y")
  22. PlaySound("x_y_2.wav",NULL,SND_FILENAME);
  23.  
  24. }
Last edited by Ancient Dragon; Dec 7th, 2007 at 7:33 am. Reason: add code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lifei is offline Offline
11 posts
since Nov 2007
Dec 7th, 2007
0

Re: Variable problem..

what makes you think you can compare integers and strings ? Ain't going to work. If the strings contain numeric digits then convert them to integers before doing the comparison.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,947 posts
since Aug 2005
Dec 7th, 2007
0

Re: Variable problem..

if it is necessary to used the variable, how should i write?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lifei is offline Offline
11 posts
since Nov 2007
Dec 7th, 2007
0

Re: Variable problem..

Are you new to c and c++ languages? You are asking a 1st semester student type of question. If you are then attempting to write an MFC program is way beyond your current level of knowledge. Get an introduction to computer programming book and start studying from page 1. Then in a year or so you will be ready for that MFC program.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,947 posts
since Aug 2005
Dec 21st, 2007
0

Re: Variable problem..

Click to Expand / Collapse  Quote originally posted by lifei ...
Can i know what's wrong with the below source code? can i put the variable x, y like this? How it can't work?
c++ Syntax (Toggle Plain Text)
  1. #include <Windows.h>
  2. #include <mmsystem.h>
  3. #pragma comment (lib,"winmm.lib")
  4.  
  5. int ,x,y;
  6. void CTestingDlg::OnPlay()
  7. {
  8. // TODO: Add your control notification handler code here
  9.  
  10. UpdateData(TRUE);
  11.  
  12. CString strFreq;
  13. CString strHL;
  14.  
  15. strFreq = m_strFreq;
  16. strHL = m_strHL;
  17.  
  18. strFreq.MakeUpper();
  19. strHL.MakeUpper();
  20.  
  21. if(strFreq=="x" && strHL=="y")
  22. PlaySound("x_y_2.wav",NULL,SND_FILENAME);
  23.  
  24. }


a ) CString to int :

CString csNumber = "3";
int x;
x = atoi(csNumber); //defined in <cstdlib>


b) int to CString

int x = 23;
CString csNumber;
csNumber.format("%d", x);

This will do .....

Make urself comfortable with basic C++ before moving into MFC ....
Reputation Points: 11
Solved Threads: 5
Newbie Poster
Aashath is offline Offline
18 posts
since Dec 2007
Dec 21st, 2007
0

Re: Variable problem..

You have an extra comma (',') before the x... Is that your question, and is that even a problem?
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Brent.tc is offline Offline
90 posts
since Oct 2006
Dec 23rd, 2007
0

Re: Variable problem..

I think the address befor var may be the reason
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kunals is offline Offline
1 posts
since Dec 2007
Dec 23rd, 2007
0

Re: Variable problem..

int ,x,y;
Delete the comma.

C++ Syntax (Toggle Plain Text)
  1. strFreq.MakeUpper();
  2. strHL.MakeUpper();
  3.  
  4. if(strFreq=="x" && strHL=="y")
You made those strings into upper-case and then you compare it with lower-case string.
Reputation Points: 350
Solved Threads: 63
Posting Pro
invisal is offline Offline
562 posts
since Mar 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Visual C++ 08 Express compiling issues...
Next Thread in C++ Forum Timeline: Need help - C++ program to determine area of triangle NOT using fstream





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC