CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Cool Window autocloses

    Hello I am a student taking a c++ class and our first assignment is to make a program that takes 5 numbers and adds them
    now i have a basic outline but when it adds and displays the answer the window closes any thoughts

    #include "stdafx.h"
    int
    main(void)
    {

    char first, middle, last;
    int number_1;
    int number_2;
    int number_3;
    int number_4;
    int number_5;
    int total_numbers;
    printf("Program Written By Ryan Kiesel\nLast Updated October 28-2009\n\n\n ");

    printf("\nType your Initials> ");
    scanf( "%c%c%c", &first, &middle, &last);

    printf("\nPress a Number> ");
    scanf( "%d", &number_1);
    printf("\nPress a Number> ");
    scanf( "%d", &number_2);
    printf("\nPress a Number> ");
    scanf( "%d", &number_3);
    printf("\nPress a Number> ");
    scanf( "%d", &number_4);
    printf("\nPress a Number> ");
    scanf( "%d", &number_5);

    total_numbers = number_1 + number_2 + number_3 + number_4 + number_5;
    printf("\n\n Thank you for your submission %c%c%C your total was: %d\n", first, middle, last, total_numbers);

    return(0);
    }

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: Window autocloses

    That is what happens when you run it from the IDE.
    How do you want the program to wait for?

    If you put getchar() before the return, it will wait till you press ENTER.
    If you pet _getch() before the return, it will wait till you press any key.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured