DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Donna Guest

    Logic game(forgot coede)


    int get_num(int a, int b, int c)
    {
    do
    {
    a = rand() % 10;
    b = rand() % 10;
    }
    while (a == b);
    do
    c = rand() % 10;
    while ((c == b) || (c==a));
    return (a,b,c);
    }


  2. #2
    Steve Wade Guest

    Re: Logic game(forgot coede)

    Try this:

    #include <stdlib.h>

    void get_num(int *a, int *b, int *c)
    {
    *a = rand() % 10;
    do
    {
    *b = rand() % 10;
    } while (*a == *b);
    do
    {
    *c = rand() % 10;
    } while ((*c == *b) || (*c==*a));
    }

    void main(void)
    {
    int a,b,c;
    get_num(&a,&b,&c);
    }

    You must pass the address of the variables you want to return. I'm assuming
    that the code should return 3 different numbers...

    Steve



    "Donna" <pooh036@home.com> wrote in message news:39ea271b$1@news.devx.com...
    >
    > int get_num(int a, int b, int c)
    > {
    > do
    > {
    > a = rand() % 10;
    > b = rand() % 10;
    > }
    > while (a == b);
    > do
    > c = rand() % 10;
    > while ((c == b) || (c==a));
    > return (a,b,c);
    > }
    >




  3. #3
    Danny Kalev Guest

    Re: Logic game(forgot coede)

    you can't return three values from a function. The compiler simply
    returns the last one in a comma expression such as
    return (a,b,c);

    What you really want is this:
    return a*100 + b*10 + c;
    Danny

    Donna wrote:
    >
    > int get_num(int a, int b, int c)
    > {
    > do
    > {
    > a = rand() % 10;
    > b = rand() % 10;
    > }
    > while (a == b);
    > do
    > c = rand() % 10;
    > while ((c == b) || (c==a));
    > return (a,b,c);
    > }


  4. #4
    Donna Guest

    Re: Logic game(forgot coede)


    How do I make a two column chart. I need to keep track of players entry and
    score. They have to guess the number the function chose until the computer
    returns PPP. P = right digit right place, n = right number wrong place and
    z = no number and all P's have to come first.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links