how to use while loop

Write your question here. when T1>T2 it works. but when T2>T1 it goes to infinity. thanks for help!




#include <iostream>

using namespace std;

int main()

{

int T1,T2;
double V;
const double rate=0.61;


cout <<"Enter The Start Tempeture:";

cin >>T1;


cout <<"Enter The End Tempeture:";

cin >>T2;
V=331.3+rate*T1;
cout.setf(ios::fixed, ios::floatfield);
cout.setf(ios::showpoint);
cout.precision(1);

while(T1 > T2)
{
V=331.3+rate*T1;
cout<<"At "<<T1<<" degrees celsiu the velocity of sound is "<<V<<endl;
T1-=1;
}
swich
while(T1 <T2)
{
V=331.3+rate*T1;
cout<<"At "<<T2<<" degrees celsiu the velocity of sound is "<<V<<endl;
T1-=1;

}

while(T1 == T2)
{
V=331.3+rate*T1;
cout<<"At "<<T1<<" degrees celsiu the velocity of sound is "<<V<<endl;
T1-=1;
}

i fixed it. thanks. the second should be t2-=1
You're welcome.
Topic archived. No new replies allowed.