Task: It is necessary to translate ° C to ° F, while the output should look like:

Введите градусы цельсия: 43°C = 200°F 20°C = 130°F 56°C = 280°F 

Celsius degrees are entered from the keyboard, Fahrenheit degrees are counted in the program. It is necessary to implement the output EXACTLY, everything else I know.

  • The problem is that you need to display the degree symbol? - KoVadim

2 answers 2

 cout << setw(2) << t_c << "°C = " << setw(3) << t_f << "°F\n"; 

If more attracts C -

 printf("%2d°C = %3d°F\n",t_c,t_f); 

Did it interest you?

About "cleaning the console" - if you want to remove everything from the console so that it is completely empty, and then display the text - then this is not provided by the standard, it already needs console functions. Or run a large number of newline characters :)

Or do you need something else?

  • The very first would work, but I enter the Celsius manually and consider the Fahrenheit and now I need a conclusion as above - Vyacheslav
  • Those. Do you want to add to user input? Standard - I do not see the possibility: the user must confirm the entry by pressing Enter. You need to use console functions like getch() , intercept each keystroke, collect the number yourself, press Enter to perform calculations and display the result ... - Harry
  • Google suggests that there is a ncurses port in Windows (the question looks like this). So you can. - avp
  • @avp Of course you can. But NOT STANDARD LANGUAGE . And using the operating system API - easily. I haven’t looked at <conio.h> long time, but at the time of it there was exactly a function like clrscr() . In the end, it’s not for nothing that Windows has a whole set of console functions available ... - Harry

In short, I decided this way: I created an array in which I added Celsius and Fahrenheit in turn, and cycled the conclusion:

 int Mass[100]; next: cout << "Введите температуру в фаренгейтах:\n"; if (i > 0) { for (int j = 0; j <= i; j++) { if (Mass[j] != 0) { int d = Mass[j]; j++; if (d > 0) cout.setf(ios::showpos); cout << d << "°F" << " = " << Mass[j] << "°C\n"; } } i++; } cin >> farh; cel = (farh - 32) * 5 / 9; Mass[i] = farh; i++; Mass[i] = cel; system("cls"); if (i >= 100) { i = 0; } goto next;