[RESOLVED] Problem implementing ToUpper
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Problem implementing ToUpper

  1. #1
    Join Date
    Nov 2013

    [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

    #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");
    			else {
    				printf ("Incorrect\n\n");
                   testResult = correctAnswer * 10;
                   printf ("You answered %i%% of the questions correctly\n\n",testResult);
                   printf ("Would you like to have another go? Y or N\n\n");
                   scanf (" %c", &repeatTest);
                    if (repeatTest=='N' || repeatTest=='n'){
                            return 0;
    Any responses would be appreacted

  2. #2
    Join Date
    Apr 1999

    Re: Problem implementing ToUpper

    Quote Originally Posted by cassas00 View Post
    I have searched and tried so many combinations to implement ToUpper into my program but it simply doesn't work
    I'm coding in C#
    Some advice -- don't use C# as a guide in attempting to write C++ code.


    Paul McKenzie

  3. #3
    Join Date
    Nov 2013

    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!

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012

    Re: [RESOLVED] Problem implementing ToUpper

    while (repeatTest=='Y' || repeatTest=='y')
    while(toupper(repeatTest) == 'Y')
    note lowercase.

    you could also have
    repeatTest = toupper(repeatTest);
    after the scanf.

    You also need
    #include <ctype.h>
    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++17 Compiler: Microsoft VS2017 (15.6.3)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)