Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Input and output formatting in c++

$
0
0

Hi all, I'm a newbie at C++ and hence my code might seem primitive.

I came across this question: Write a C++ program to convert Celsius degrees to Fahrenheit. The program should request the starting Celsius value, the number of conversions to be made, and the increment between Celsius values. The display should have appropriate headings and list the Celsius value and the corresponding Fahrenheit value. Use the relationship that Fahrenheit = (9.0 / 5.0) * Celsius + 32.0.

I am going to use while for the looped iterations. But the problem is how to accept data while keeping the tabular formatting of output intact. Every time I call cin it breaks the line. What do i do to resolve this. I am attaching a code outline. Suggestions appreciated.

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
int maxnum, counter;
double num;

cout << "Please enter the no. of data conversions you want to do: ";
cin >> maxnum;
cout << "This program will now let you do " << maxnum << " data conversions." << endl;

counter = 1;

cout << "Celsius            Farenheit" << endl 
        << "-------             -----------" << endl;

while (counter <= maxnum)
{


    counter++;
}

return 0;
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>