Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8912299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:09:51+00:00 2026-06-15T04:09:51+00:00

this is my first time using Stack Overflow, and I must warn you that

  • 0

this is my first time using Stack Overflow, and I must warn you that I only started to learn C earlier this week. I am trying to write a simple program that will find which color has the greatest value out of the RGB spectrum. It has a manual input for each color, but when It is finished, I am getting 2 odd numbers ranging in the millions. Could somebody help a noob? Here is the code that I’ve written so far:

#include <stdio.h>

int main()
{
    int mm, m;
    int hh, h;
    int r, g, b, c;

    printf("Enter Value For Red (0-255)\n");
    scanf("%d", &r);
    printf("Enter Value For Green (0-255)\n");
    scanf("%d", &g);
    printf("Enter Value For Blue (0-255)\n");
    scanf("%d", &b);


    if ( r > g );
        if ( r > b );
            mm = r;
            if ( g > b );
                m = b;
            if ( b > g );
                m = g;
       if ( r < b );
            mm = b;
            m = g;
    if ( g > r );
        if ( g > b );
            mm = g;
            if ( r > b );
                m = b;
            if ( b > r );
                m = r;
        if ( g < b );
            mm = b;
            m = r;

    printf("%d\n", &mm);
    printf("%d\n", &m);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:09:52+00:00Added an answer on June 15, 2026 at 4:09 am
    printf("%d\n", &mm);
    printf("%d\n", &m);
    

    Should be:

    printf("%d\n", mm);
    printf("%d\n", m);
    

    The & gets the address of the variable. When you’re setting a variable via scanf() you need to give the address so that it can be set. When you’re printting the value of a variable via printf() you need to just provide the name, not the address.

    What you’re seeing right now is the address of where your variables are stored on the stack as a decimal number.


    Side note, your code doesn’t work the way you think it does:

    if ( r > g );
        if ( r > b );
            mm = r;
            if ( g > b );
                m = b;
            if ( b > g );
                m = g;
       if ( r < b );
            mm = b;
            m = g;
    

    It takes more then indentation to get this working, right now it’s doing the following:

    mm = r;
    m = b;
    m = g;
    mm = b;
    ...
    

    everytime you run it, because the if’s are being chucked. You can’t have ; after an if statement or it doesn’t do what’s below it. Also use curly brackets { } to make a scope to do more then one thing:

    if ( r > g )
    {
        if ( r > b )
        {
            mm = r;
            if ( g > b )
                m = b;
            if ( b > g )
                m = g;
       }
       if ( r < b )
       {
            mm = b;
            m = g;
        ...
    

    Is what you wanted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time using Stack Overflow, so if I've done something wrong
This is my first time posting to Stack Overflow. I'm trying to build a
This is my first time using XML documents. What I'm trying to do is
First of all, this is my first post in Stack Overflow and I'm trying
First time posting in Stack Overflow, hope I'm doing this right. I'm writing an
This is my first time posting on Stack Overflow, so hopefully I did everything
This is my first time using this site and I am quite new to
This is my first time using lightbox which uses jquery framework. But when I
This is my first time using an external library, and I'm a bit nervous
This is my first time using jQuery and I am pleased to get my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.