#include <iostream>
#include <string>
#include <conio.h>
#define ESC 27
using namespace std;
int main() {
char ch;
int sum = 0;
do {
ch = _getch();
if (ch == ESC) {
cout << "Output of the program:\n" << sum;
putchar('\n');
} else {
cout << ch;
sum += (int)ch;
}
} while (ch != ESC);
system("pause");
return 0;
Объяснение:
#include <iostream>
#include <string>
#include <conio.h>
#define ESC 27
using namespace std;
int main() {
char ch;
int sum = 0;
do {
ch = _getch();
if (ch == ESC) {
cout << "Output of the program:\n" << sum;
putchar('\n');
} else {
cout << ch;
sum += (int)ch;
putchar('\n');
}
} while (ch != ESC);
system("pause");
return 0;
}
Объяснение: