Dev C++ Cout Endl

P: 1
Here is the code..
#include <iostream>
main()
{
double f_temp, k_temp, c_temp, temp;
char ch, quit;
std::cout << ' *********** Temprature Conversion Calculator **************';
std::cout << 'nn Please enter the temprature unit for which you want the coverison ';
std::cout << 'n 1. F for Fahrenheit to Celcius and Kalvin';
std::cout << 'n 2. C for Celsius to Fahrenheit and Kalvin';
std::cout << 'n 3. K for Kalvin to Fahrenheit and Celcius';
startagain:
std::cout << 'nn Please enter you choice: ';
std::cin >> ch;
switch(ch)
{
case 'f':
case 'F':
std::cout << ' Please enter temprature in Farhenheit: ';
std::cin >> f_temp;
c_temp = (f_temp - 32) * 5/9;
k_temp = (f_temp + 459.67) * 5/9;
std::cout << ' Celcius =' << c_temp;
std::cout << 'n Kelvin =' << k_temp;
std::cout << 'n Do you want to calculate another value (y/n): ';
std::cin >> quit;
if (quit 'y' || quit 'Y')
goto startagain;
break;
case 'c':
case 'C':
std::cout << ' Please enter temprature in Celcius: ';
std::cin >> c_temp;
k_temp = c_temp + 273.15 ;
f_temp = c_temp * 9/5 + 32;
std::cout << ' Kelvin =' << k_temp;
std::cout << 'n Farhenheit =' << f_temp;
std::cout << 'n Do you want to calculate another value (y/n): ';
std::cin >> quit;
if (quit 'y' || quit 'Y')
goto startagain;
break;
case 'k':
case 'K':
std::cout << ' Please enter temprature in Kelvin: ';
std::cin >> k_temp;
c_temp = k_temp - 273.15 ;
f_temp = (k_temp - 273.14) * 9/5 + 32;
std::cout << ' Celcius =' << c_temp;
std::cout << 'n Farhenheit =' << f_temp;
std::cout << 'n Do you want to calcute another value (y/n): ';
std::cin >> quit;
if (quit 'y' || quit 'Y')
goto startagain;
break;
default:
std::cout << 'n Invalid Choice';
}
std::cout << endl<<endl;
system('pause');
}
Dev C++ Cout Endl
  • Related Questions & Answers

Home topics c / c questions 'endl' was not declared in this scope + Ask a Question. Post your question and get tips & solutions from a community.

  • Selected Reading
Dev

Dev C Cout Endl Form

C++Server Side ProgrammingProgramming

C++ Cout Include

In this section we will see what are the differences between cout << endl, and cout “n” in C++. We should use cout << “n” in different cases, and avoid endl.

So why we should avoid the std::endl while printing lines into console or a file. We use std::endl for creating a newline after the current line. For few lines of IO operations, it is not making any problems. But for large amount of IO tasks, it decreases the performance.

C++ Cout Endl

The endl is used to create new lines, but it does not send to the new line only, after sending the cursor to the next line it flushes the buffer each time.

Dev C++ Cout Endless Love

The flushing of buffers is not the programmers task; the operating system is responsible for it. Each time it requests for flushing, it requests to the operating system. This requesting is comparatively expensive. And we don’t really need to flush buffers every time after writing some lines. The IO streams automatically clears the buffer when it is full.

Endl In C

If we analyze the required time to write nearly 100000 lines of texts into file by using std::endl, and using ‘n’ we can easily see the difference. The code which is using std::endl is taking nearly two times more times to complete the task compared to using ‘n’ after it.