Thread: A newbieÂ’s first task in C - Questions

  1. #1
    Registered User
    Join Date
    Oct 2020
    Posts
    1

    A newbieÂ’s first task in C - Questions

    Hello everyone.
    So Im a newbie in the C-programming business and this is my first task with questions that I have. This is the practical task:

    A factory in an industrial zone produces 1,000 devices daily to local consumption (statewide and export). Given that 0.05% of the devices manufactured in the factory are disqualified during quality tests, disassembled and their parts are recycled, write a #C program that calculates how many normal devices can be supplied daily for local distribution and export, and how many devices are disassembled after disqualification.

    So that's my program, but I canÂ’t get it right, both in terms of the numbers and in terms of half a device that will be calculated as one whole device. So how should I fine-tune the code to get everything done properly?

    Code:
    #include<stdio.h>
    void main()
    {
        int x,y,z;
        x = 1000; y = 1000 * 0.0005; z = x - y;
            printf("Proper devices that can be supplied daily for distribution and export: %d \n", &z);
            printf("Disqualified devices (for disassembly): %d", &y);
    }
    Thanks in advance for the help.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    "printf" is an output function; I have no idea if you mean to do output or input.
    If input the "&z" is correct and printf is wrong. If output you need to use "z" instead; and, the printf is correct.

    Lookup the double type which is used for floating point numbers.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Try compiling with some warnings.
    Code:
    $ gcc -Wall main.c
    main.c:2:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
     void main()
          ^
    main.c: In function ‘main’:
    main.c:6:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]
             printf("Proper devices that can be supplied daily for distribution and export: %d \n", &z);
                    ^
    main.c:7:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]
             printf("Disqualified devices (for disassembly): %d", &y);
                    ^
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2020
    Posts
    150
    I would be better to use constants and and proper names like:
    Code:
    #define NUM_DEVICES      1000
    #define NUM_DISQUALIFIED 0.0005

  5. #5
    Registered User
    Join Date
    Nov 2018
    Location
    Amberg in upper palatinate, Bavaria
    Posts
    66
    Hi shloa4!

    It sounds like working with the normal distribution. In Europe the control limits are by 99 Percent(2.575829 sigma), the warning limits are by
    95 percent(1.95996398 simga) distance to µ(average). In USA the warning limits are by 95,44 percent (exactly 2 sigma), the control limits
    by 99.97 percent(3 sigma). From the lower control limit to the upper control limit there are in Europe (like Germany) a distance of about
    5.151658 simga. Sigma is the standard deviation of a population. With the values like in Europe(FRG) you have exactly 10000 parts per million
    where are rejects.
    With the values like in USA you have 2699.796 parts per million rejects That is a difference of 7300 parts. For example.

    Better you use double instead of int. I think to control yourself may be you can use my old Files where i wrote as a retrainee to
    a skilled worker for quality assurance.

    You can find it on a german webside:

    Infos - LibreOffice-Forum


    I hope you can use it to control your programs and it is not do difficult that it is in german language to translate it to english.

    By +- 1.96 sigma there are about 50000 parts outside this limits.


    An easy formula to calculate the CPK value where are need it to get limits is followed by those examples:

    1.96 sigma includes 95 % and a CPK value of 0.65 (about 2/3)
    1.575829 sigma includes 99 % and a CPK value of 0.65 (about 0.86)
    3 sigma includes 99.73 % and a CPK value of 1 (about 3/3)
    4 sigma includes 99.994 % and a CPK value of 1.33333 (about 4/3)
    5 sigma includes 99.99994 % and a CPK value of 1.67 (about 5/3)
    6 sigma includes 99.9999998 % and a CPK value of 2 (about 6/3)

    To calculate the number of the parts per million it is useful ti work with the normal distribution.
    Some sources where i found in web i gathered it at

    Ressource - Kleine Sammlung von Tools fur Statistik(geplagte) | dev-community.de

    Sorry, is in german too. I hop you can use it even so.
    There are sources like functions for excel like NORMDIST, NORMINV, CHIVERT, CHIINV, KONFIDECE for c and cpp.
    The size of a random sample for control parts depends from the size of a population and the Acceptable Quality Level(AQL).
    After you get the size of random example, get the acceptance number and rejection number.

    It is useful to work with Shewhart Process control charts.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Task 7.4, help
    By Franksy in forum C Programming
    Replies: 5
    Last Post: 12-18-2017, 06:01 PM
  2. Whether you can do this task?
    By rale.pop in forum C Programming
    Replies: 5
    Last Post: 05-20-2017, 12:08 PM
  3. Help me with the task please :3
    By flakee in forum C Programming
    Replies: 3
    Last Post: 03-28-2016, 08:20 AM
  4. Need help to do the big task
    By Steve Cao in forum Linux Programming
    Replies: 1
    Last Post: 07-16-2010, 02:01 PM
  5. Replies: 2
    Last Post: 12-31-2007, 11:40 AM

Tags for this Thread