I need help!

Oct 22, 2011 at 2:14pm
I am trying to generate a table of conversions from Celsius to Rankin and allows the user to enter the starting temperature and increment between lines. Print 25 lines in the table using a for loop.
This is what I have but I am getting a (fatal error LNK1169).
#include <iostream>
#include <iomanip>
using namespace std;

int main()

{
double Celsius, x;
cout << "Enter the starting temperature for Celsius ";
cin >> Celsius;
cout << " Celsius Rankin" << endl;

cout << fixed;
for (double Celsius=0; Celsius<=24 ; ++Celsius)
{
x = Celsius * 493.47;
cout << setw(7) << setprecision(4) << Celsius <<
setw(9) << setprecision(4) << x << endl;
Celsius+=5;
}
return 0;
}
Oct 22, 2011 at 2:20pm
It's a valid, if incorrect, program. Your build environment (compiler/linker) is misconfigured.
Oct 22, 2011 at 2:37pm
Thank you kind sir. Would you happen to know how to get this program to execute 25 times, because, the way it is now it executes 5 times and that is it.
Oct 22, 2011 at 3:20pm
The reason it only goes through the loop 5 times is because of this line at the end of your for loop: Celsius+=5;
Remove that, and the loop will repeat 25 times.
Oct 22, 2011 at 3:23pm
@Aaron
Your formula for getting Rankine was wrong, and the for loop, incorrect. No matter what was inputted as Celsius, the for loop sets it to zero. Here is your program, working correctly.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	float Celsius, tr;
	int x;
	
	cout << "Enter the starting temperature for Celsius ";
	cin >> Celsius;
	cout << "\t\t Celsius Rankine\n\t\t-----------------" << endl;
	for (x=0; x<24 ; x++)
	{
		tr = 1.8*Celsius+491.67;
		cout << "Celsius = "  << Celsius  << "  Celsius Rankine = " << tr << endl;
		Celsius+=5;
	}
	return 0;
} 
Oct 22, 2011 at 3:31pm
that did it! thanks!
Oct 22, 2011 at 3:45pm
You're welcome, Aaron. Set this thread as 'Solved'.
Oct 22, 2011 at 4:48pm
The way my program is now starts from 0 and disregards the users input. Anyone now how to fix that?
Oct 22, 2011 at 5:09pm
@Aaron
Why do you think the program disregards the users input.? the tr variable (Total Rankine) gets equal to the Celsius input. Tr is multiplied by 1.8, and then 491.67 is added to it. Now tr is equal to Celsius Rankine. Cout prints it to screen, The Celsius input is increased by 5 degrees, as you intended, and the whole process is done again. The x in the loop is just to increase Celsius, 25 times, as you specified in the first post.
Topic archived. No new replies allowed.