![]() |
|
#1
|
|||
|
|||
my 1st simple program, 3 slight problems.Hi, I am VERY new to Visual C++ and to learn some of the basics I have created a simple translator program which has 2 functions, learn a word (type a number and it displays and english and philippine word) and then quiz function (displays an english word and user gets to try and enter the correct Phillipiine word)
Heres my code: - CPP / C++ / C Code:
Even though the program works, ive got some slight problems that I need help with, these are: - Learn function When a character is entered into the ‘type a number’ input, program goes into an ongoing loop. Quiz function Program only recognizes the correct answer if the casing is the same as the array. If on the ‘Press 1 for another word or 2 for menu’ a character is entered then the program goes back to the main menu, but then continues through the process as if an invalid number has been entered. Please help! Thanks in advance to anyone who answers |
|
#2
|
||||
|
||||
Re: my 1st simple program, 3 slight problems.Quote:
Quote:
Quote:
I just looked a little closer at your quiz() function and noticed the following potential problems: CPP / C++ / C Code:
CPP / C++ / C Code:
And welcome to GID, and thanks for reading the guidelines first __________________
Age is unimportant -- except in cheese |
|
#3
|
|||
|
|||
Re: my 1st simple program, 3 slight problems.ive looked at the toupper() and tolower() functions, but can't seem to get them to work? Im wanting to add tolower() to: cin>>phiword; which is 'char phiword[50];'
How do I add: - int toupper(int c); to that? |
|
#4
|
||||
|
||||
Re: my 1st simple program, 3 slight problems.Code? Can't tell if you used it correctly if you don't post code.
__________________
Age is unimportant -- except in cheese |
|
#5
|
||||
|
||||
Re: my 1st simple program, 3 slight problems.Quote:
char phiword[50] means that phiword is a string, and you cant convert a string as a whole.. For example, it can be like this: CPP / C++ / C Code:
Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#6
|
|||
|
|||
Re: my 1st simple program, 3 slight problems.I think that skizer needs to decide whether we're using C or C++, because the code shown is an unfortunate mixture of both.
Mixing "cout" with strlen(...) seems counter-intuitive to me. CPP / C++ / C Code:
...looping through character by character makes for uglier code. ...also, there is no language called Philippine. You may want to consider Tagalog, Ilocano and Pangasinan (among others) as viable choices. Take Care. Rob! |
|
#7
|
||||
|
||||
Re: my 1st simple program, 3 slight problems.Not really. strlen() is an approved way to deal with c-strings in either C or C++.
Opinion alert!!! Also, notice the thread title: "my 1st simple program" transform() is a higher level string manipulation function and a new programmer is probably not ready for it IMAO. The loop is a little more understandable because it's so low level, and a new person gets to understand the concept of loops and arrays. __________________
Age is unimportant -- except in cheese |
|
#8
|
|||
|
|||
Re: my 1st simple program, 3 slight problems.I researched into this problem and found that if i add this after the inputs which where causing problems when entering a charachter then it works fine.
CPP / C++ / C Code:
I now just need a hand in getting whatever word is inputted to be title case sensitive 'JustLikeThis' so it matches the arrays. Thanks in advance. My full code ATM is: - CPP / C++ / C Code:
|
|
#9
|
||||
|
||||
Re: my 1st simple program, 3 slight problems.I guess I wasn't clear before.
NO NO NO NO!!!!! Never call main()!! Never never never! This may cause a lot of problems during the exection of the program and is not recommended in any way, shape, or form. Please get out of this habit now before it's too late. You return to main() by using the return statement from the function! What you're doing is like starting the car with the key every time you stop at a light -- but never shutting the engine off! And you don't want to call quiz() while you are in quiz()! You want to go to the bottom of your loop and simply lett the loop start again. I'm assuming you posted here to get help. Please heed the help given. __________________
Age is unimportant -- except in cheese |
|
#10
|
|||
|
|||
Re: my 1st simple program, 3 slight problems.Quote:
Opinion alert!!! Mixing "cout" with strlen(...) seems counter-intuitive to me...just sharing my opinion. ...the program may be simple, but that doesn't necessarily mean that the answer needs to be simpleton. I disagree that somehow that transform() is so much more difficult than any other standard library function, including strlen(). The reason someone who is not a newbie would consider it is probably because of their familiarity with standard C-library string manipulation functions and not consider it from the perspective of a newbie, which would be what is the simplest thing that works? Also, why even use C-string functions in C++? If we are trying to decide on a language, maybe using C is a good idea and maybe using C++ is a good idea, but intermixing the two rarely seems like a good idea to me. (opinion alert necessary?) If the purpose is to teach conditional operations and looping, fine, then strtok is a good example. If the goal is to solve the challenge of implementing a simple, easy to understand and write "string case changer," (assuming C++ is the desired language), I fail to see why my example is any more difficult for a newcomer to learn. I'm quite certain that I wouldn't want to teach someone to use C in a C++ application simply because the concept of looping is somehow more low-level than making a single standard library function call. And, how much more difficult would it be to teach looping (and appropriate constraints for the conditional(s) needed to control the looping) and character-by-character operations compared to pointing to a simple standard library function that does it all in one fell swoop? It seems inappropriate to me to offer advice that suggests that serendipitously mixing the two languages is a perfectly acceptable choice. I mean, if you're going to use C++ you wouldn't expect the code to be littered with printf would you? And, if it was so littered, would you recommend using cout for C++? If so, why not recommend more C++ centric choices, too? I'm just trying to understand where you draw the line. I'm fully aware of the possibility that there are going to be differing opinions <grin> Of course, as a 1st simple program, which I doubt that this is actually the first ever for this individual, "Hello, World!" works a lot better and even basic looping constructs suggest an increased level of learning! However, there is a truly easy way to acheive the desired title case as requested by the thread originator. I now just need a hand in getting whatever word is inputted to be title case sensitive 'JustLikeThis' so it matches the arrays. ...even though the example given above isn't true title case, rather it is camel-backed, all of the words in the array are single words. One can imagine the difficulty of teaching the computer how to negotiate multiple words so that camel-backed case is applied. Since the strings are all single words, it is easy: CPP / C++ / C Code:
...added after the call to transform does the job quite nicely, very simply, very easy-to-read and understand. But, that is obviously just my opinion. (Opinion Alert opportunity? No? Bummer dude.) <grin> Take Care. Rob! |
Recent GIDBlog
Halfway done! by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| little help with a simple program | patito | C++ Forum | 3 | 08-Sep-2005 08:40 |
| Help with simple math table program (was a SIMPLE program) | Bubba | C Programming Language | 3 | 09-Mar-2005 12:40 |
| Help with a simple program. | bluedragon27 | C Programming Language | 1 | 16-Nov-2004 15:40 |
| Please Help, problems writing newbie c program | soulfly | C Programming Language | 14 | 04-Mar-2004 15:16 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The