CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Feb 2012
    Posts
    68

    Help using a character as parameter

    I have a multiple choice function below that is part of a larger program but I am having trouble having it operate with characters as inputs and arguments. It has to be a character input, but I kinda want it to act like an integer, how do i do that?


    Code:
    void addition(int *Preward) //function that is called by the users selection
    {
     
     
        int random1, random2;
        int order;
        int one, two, three;
        int rando1, rando2;
        char a, b, c;                              // ERROR
        char userselect;                         //ERRRORR
        srand(time(NULL)); //generates fresh numbers each time.
        random1 = 1+(rand()%99); // from 1-99
        random2 = 1+(rand()%99); // from 1-99
        rando1 = 2+(rand()%198); // 2 to 198
        rando2 = 2+(rand()%198); // 2 to 198
        order = 1+(rand()%3);
     
     
        switch(order){
            case 1: printf("\n%d + %d = ", random1, random2);
                one = (random1+random2);
                two = (rando1);
                three = (rando2);
                printf("\n select from the following\n a) %d b) %d  c) %d\n", one, two, three);
                scanf("%c", &userselect);                        //ERROR
                    if (userselect == a){                          //ERROR
                        printf("Congratulations\n\n");
                        *Preward = 1;
                    }
                    else{
                        printf("incorrect, correct answer is a\n\n");
                     }break;
    Last edited by chucker; February 20th, 2012 at 09:33 PM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured