-
November 6th, 2013, 05:46 AM
#1
[RESOLVED] Problem implementing ToUpper
I have searched and tried so many combinations to implement ToUpper into my program but it simply doesn't work so I'm resorting to the message boards!
I'm coding in C# and I use Visual 6 C++ at Uni and Codeblocks at home and it works on neither.
Currently I'm using (repeatTest=='Y' || repeatTest=='y') but I want to implement <ctype.h> and ToUpper so that even if a lowercase y is entered it still accepts it.
I've tried
char repeatTest = repeatTest.ToUpper();
repeatTest = repeatTest.ToUpper();
both say 'ToUpper' in something not a structure or union
and many other combinations.
Here's my working code
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
char repeatTest='Y';
while (repeatTest=='Y' || repeatTest=='y')
{
char answer=0, correctAnswer=0, questionNumber=1, testResult=0, NumberOfQuestions=1;
srand (time(0));
printf ("Test will begin, good luck\n\n\n\n");
for (NumberOfQuestions=0; NumberOfQuestions!=10; NumberOfQuestions++) {
int randomValue1=rand()%12+1;
int randomValue2=rand()%12+1;
printf("%i. What is %i x %i? ",questionNumber, randomValue1, randomValue2);
scanf("%i", &answer);
if (answer==(randomValue1*randomValue2)){
printf ("Correct\n\n");
++correctAnswer;
++questionNumber;
}
else {
printf ("Incorrect\n\n");
++questionNumber;
}
}
testResult = correctAnswer * 10;
printf ("You answered %i%% of the questions correctly\n\n",testResult);
"\n\n";
printf ("Would you like to have another go? Y or N\n\n");
scanf (" %c", &repeatTest);
if (repeatTest=='N' || repeatTest=='n'){
return 0;
}
system("cls");
}
system("pause");
}
Any responses would be appreacted
-
November 6th, 2013, 06:00 AM
#2
Re: Problem implementing ToUpper
Originally Posted by cassas00
I have searched and tried so many combinations to implement ToUpper into my program but it simply doesn't work
http://www.cplusplus.com/reference/cctype/toupper/
Some advice -- don't use C# as a guide in attempting to write C++ code.
Regards,
Paul McKenzie
-
November 6th, 2013, 06:26 AM
#3
Re: Problem implementing ToUpper
Ah, I think I'm getting too far ahead of myself. I'll wait to see how my tutor implements it in c# in my upcoming lessons rather than using c++ code lol thanks!
-
November 6th, 2013, 06:33 AM
#4
Re: [RESOLVED] Problem implementing ToUpper
Code:
while (repeatTest=='Y' || repeatTest=='y')
becomes
Code:
while(toupper(repeatTest) == 'Y')
note lowercase.
you could also have
Code:
repeatTest = toupper(repeatTest);
after the scanf.
You also need
at the beginning of the program.
Paul offered some good advice - although in certain respects c# bears some resemblance to c++, don't use it as a guide as to how to write c++ programs.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|