.exe program closing

+1 Christian Chiang · February 14, 2015
Hello,

I have written a simple code from one of the Bucky's tutorial. Everything is fine while I run the .exe outside code blocks but the problem is that as soon as I type the final input the program closes automatically.

Note: The code runs great inside codeblocks.


#include
#include

int main()
{
    float grade1;
    float grade2;
    float grade3;

    printf("Enter your 3 test grades: \n");
    scanf(" %f", &grade1);
    scanf(" %f", &grade2);
    scanf(" %f", &grade3);

    float avg = (grade1 + grade2 + grade3)/3;
    printf("Average: %.2f \n", avg);

    if(avg >= 90){
        printf("Grade: A");
    }else if(avg >= 80){
        printf("Grade: B");
    }else if(avg >= 70){
        printf("Grade: C");
    }else if (avg >=60){
        printf("Grade:D");
    }else{
        printf("You're dumb");

    return 0;
    }

}


Post a Reply

Replies

Oldest  Newest  Rating
+1 Abdullah Nauman · February 14, 2015
Just add 
getchar();


At the end. Then it will have you press enter at the end in order to terminate the program.
0 Lazar Bulic · February 14, 2015
I guess you are trying to run the .exe in the Release folder. Try running one in the Debug folder. :)
0 David Drew · February 15, 2015
I don't know abou this language but its like c plus plus
In c plus plus you have to add at the end system("pause"); before return0;
so the pro don't close when you run it ... 
I am a beginner don't know if this helpful....
0 Christian Chiang · February 15, 2015
getchar();

Didn't work for me, placed it before return 0; and still closed the program automatically.
How ever, 
system("pause");


worked as expected.
Thanks!
  • 1

C

107,322 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator