0

This program takes 2 ints (a and b) and is supposed to print their product. It terminates without printing the last line, though:

Problem:what makes the program doesn´t give the result that u want and closes beforehand ? is there something wrong with this line?

        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;
}

1 Answers1

0

As others have said in the comments, you probably just aren't seeing the last line of output before the program exits, because there's nothing to keep the program running and the window open after it prints it.

Try adding something like this before the return statement:

std::cout << "Press any key to exit.";
char dummy;
std::cin >> dummy;
Ixrec
  • 966
  • 1
  • 7
  • 20