Thread: help me

  1. #1
    Registered User
    Join Date
    Jul 2014
    Posts
    2

    Unhappy help me

    In digital world colors are specified in Red-Green-Blue (RGB) format, with values of R,G,B vaying on an integer scale from 0 to 255. In print publishing the colos are mentioned in Cyan-Magenta-Yellow-Black (CMYK) format, with values of C,M,Y and K varying on a real scale from 0.0 to 1.0 . Write a program that converts RGB color to CMYK coor as per the following formulate:
    White= Max(Red/255,Green/255,Blue/255)
    Cyan=(White-Red/255)/White
    Magenta= (White-Green/255)/White
    Yellow=(White-Blue/255)/White
    Black=1-White
    Note that is RGB values are all 0, then the CMY values are all 0 and the K value is 1.

    Code:
    #include <stdio.h>
    main()
    {float white,red,green,blue,cyan,magneta,yellow,black;
    printf("Enter r,g,b values");
    scanf("%f%f%f",&red,&green,&blue);
    white=max((red/255),(green/255),(blue/255));
    cyan=((white-(red/255)/(white));
    magneta=((white-(green/255)/(white));
    yellow=((white-(blue/255)/(white));
    black=1-white;
    printf("the values of cyan %f\nmganeta %f\nyellow %f\n black %f\n\n\n\n,cyan,magneta,yellow,black);
    return 0;
    }
    for this problem i write like this but i didnt get the answer shows error
    it shows error on max help me
    Last edited by eswa007; 07-26-2014 at 04:51 AM. Reason: i forget to mention one thing

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    You should post your warnings and error messages. Also, make sure you're compiling with warnings turned up. This is what I got.

    Code:
    /*
    main.c|3|warning: return type defaults to 'int'|
    main.c||In function 'main':|
    main.c|7|warning: implicit declaration of function 'max'|
    main.c|8|error: expected ')' before ';' token|
    main.c|12|warning: missing terminating " character|
    main.c|12|error: missing terminating " character|
    main.c|14|error: expected declaration or statement at end of input|
    main.c|4|warning: unused variable 'black'|
    main.c|4|warning: unused variable 'yellow'|
    main.c|4|warning: unused variable 'magneta'|
    ||=== Build finished: 3 errors, 6 warnings ===|
    */
    >> main.c|3|warning: return type defaults to 'int'|

    This is saying "main()" should be defined as returning an int; i.e. "int main(void)"

    >> main.c|7|warning: implicit declaration of function 'max'|

    This is saying there is no function called "max", because the code on that line has syntax that implies you are calling a function named "max". I suspect you just blindly copied that from the assignment description, without realizing what it means.

    >> main.c|8|error: expected ')' before ';' token|

    This plainly says you're missing a ')' in the "cyan" formula. In fact, I recommend you count all of your opening and closing parenthesis on each line to make sure they're all there.

    >> main.c|12|warning: missing terminating " character|
    >> main.c|12|error: missing terminating " character|

    This plainly says you're missing a closing " character in your "printf()" statement. Look at it, you need to end the string after the last '\n'.

    >> ...

    Those last few warnings are the result of earlier warnings/errors, so fixing those should get rid of them. I suspect there will still be problems for you to fix.

    Code:
    white=max((red/255),(green/255),(blue/255));
    While the assignment was kind enough to write most of the formulas out in a way that you could just copy/paste into your program, they are not all way. Think carefully about the line of code above.

  3. #3
    Registered User
    Join Date
    Jul 2014
    Posts
    2

    Smile

    Quote Originally Posted by Matticus View Post
    You should post your warnings and error messages. Also, make sure you're compiling with warnings turned up. This is what I got.

    Code:
    /*
    main.c|3|warning: return type defaults to 'int'|
    main.c||In function 'main':|
    main.c|7|warning: implicit declaration of function 'max'|
    main.c|8|error: expected ')' before ';' token|
    main.c|12|warning: missing terminating " character|
    main.c|12|error: missing terminating " character|
    main.c|14|error: expected declaration or statement at end of input|
    main.c|4|warning: unused variable 'black'|
    main.c|4|warning: unused variable 'yellow'|
    main.c|4|warning: unused variable 'magneta'|
    ||=== Build finished: 3 errors, 6 warnings ===|
    */
    >> main.c|3|warning: return type defaults to 'int'|

    This is saying "main()" should be defined as returning an int; i.e. "int main(void)"

    >> main.c|7|warning: implicit declaration of function 'max'|

    This is saying there is no function called "max", because the code on that line has syntax that implies you are calling a function named "max". I suspect you just blindly copied that from the assignment description, without realizing what it means.

    >> main.c|8|error: expected ')' before ';' token|

    This plainly says you're missing a ')' in the "cyan" formula. In fact, I recommend you count all of your opening and closing parenthesis on each line to make sure they're all there.

    >> main.c|12|warning: missing terminating " character|
    >> main.c|12|error: missing terminating " character|

    This plainly says you're missing a closing " character in your "printf()" statement. Look at it, you need to end the string after the last '\n'.

    >> ...

    Those last few warnings are the result of earlier warnings/errors, so fixing those should get rid of them. I suspect there will still be problems for you to fix.

    Code:
    white=max((red/255),(green/255),(blue/255));
    While the assignment was kind enough to write most of the formulas out in a way that you could just copy/paste into your program, they are not all way. Think carefully about the line of code above.
    thanks alot sir im new for c programming i have interest to learn but i dont know what to do. thats is the reason for lot and lots of mistake sir.

  4. #4
    Registered User zub's Avatar
    Join Date
    May 2014
    Location
    Russia
    Posts
    104
    Note that you do not need immediate values​​ R, G, B; you need R/255, G/255, B/255 only. So, you can divide one time.

    In addition, it is considered good habit to specify the type of real numbers: 255.0 (double) or 255.0f (float), not 255 (integer).

    You need to write function max independetly. Hint: write two functions, max2 (should return the larger of two numbers) and max3 (will use max2 for your convenience).
    Our goals are clear, tasks are defined! Let's work, comrades! -- Nikita Khrushchev

Popular pages Recent additions subscribe to a feed