2015-01-02 3 views
0

이 프로그램은 2 정수 (ab)를 취해 해당 제품을 인쇄합니다. 그래도 마지막 줄을 인쇄하지 않고 종료됩니다.결과 계산 전에 C++ 프로그램 종료

문제점 : 프로그램을 만들면 원하는 결과가 나오지 않고 미리 닫힙니다. 이 줄에 문제가 있습니까? 그것을 인쇄 후 프로그램을 실행하고 열려있는 창을 유지하는 것이 없기 때문에 다른 사람의 의견에, 당신은 아마 프로그램이 종료하기 전에 출력의 마지막 줄에 나타나지 않는 말했듯이

 std::cout << "Product of entered numbers = " << c << std::endl; 
// first program, printing chars and multiplying 2 integers 

#include <iostream> 

int main() 
{ 
    printf("Characters: %c %c \n", 'a', 65); 
    printf("Decimals: %d %ld\n", 1977, 650000L); 
    printf("Preceding with blanks: %10d \n", 1977); 
    printf("Preceding with zeros: %010d \n", 1977); 
    printf("Some different radices: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100); 
    printf("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416); 
    printf("Width trick: %*d \n", 5, 10); 
    printf("%s \n", "A string"); 
    int a, b, c; 

    std::cout << "Enter two numbers to multiply\n"; 
    std::cin >> a >> b; 

    c = a*b; 
    std::cout << "Product of entered numbers = " << c << std::endl; 

    return 0; 
} 
+0

을 당신은 마지막 줄 오른쪽 인쇄 볼 수 없을거야? 다른 라인은 모두 보이니? – Useless

+2

팁 : C 스타일 IO에 신경 쓰지 마십시오. C++ 스트림이 더 안전합니다. –

+0

@Useless : 예 .. n tq 4 팁! –

답변

0

.

시도 반환 문 앞에 이런 식으로 뭔가를 추가 :

std::cout << "Press any key to exit."; 
char dummy; 
std::cin >> dummy; 
관련 문제