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

Thread: Compiled Program crashed/stopped working

  1. #1
    Join Date
    May 2018
    Posts
    1

    Compiled Program crashed/stopped working

    here is the code
    Code:
    #include <stdio.h>
    int main ()
    {
        int x,y,z;
        printf ("Enter Cost , Profit, Selling Price");
        scanf ("%d",x);
        scanf ("%d",y);
        scanf ("%d",z);
        if ((x + y) > z)
        {
            printf("Commercial Invoice");
        } else {
            if ((x + y) == z)
            {
                printf("Free of cost Invoice");
            } else {
                if ((x + y) < z)
                {
                    printf("Error");
                }
            }
        }
    }
    here is the output

    Code:
    Enter Cost , Profit, Selling Price_
    but when i enter something it crashes
    Last edited by 2kaud; May 18th, 2018 at 09:25 AM. Reason: Edited code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,459

    Re: Compiled Program crashed/stopped working

    [When posting code, please use code tags rather than quote tags so that the code is readable. Go Advanced, select the formatted code and click '#']

    For scanf(), you need to specify the address to which the data will be read. So

    Code:
    scanf("%d", &x);
    and likewise for the others.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.7)

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)