I'm writing a simple program for my chemistry class that does ideal gas law conversions. I have successfully gotten the program to do the conversions and calculations but I cannot get it to loop. I would like it to ask the user, "Do you need to perform another conversion?". If the user answers yes, it loops, if the answer is no, it stops. I'm pretty new to all this (surprise, surprise eh?) so bare with me. Here is the code I have thus far. Any help would be greatly appreciated!
Thanks in advance!Code:char yes; int main() { do { float pressure; cout<<"Define P: "; cin>>pressure; float volume; cout<<"Define V: "; cin>>volume; float nofmoles; cout<<"Define n: "; cin>>nofmoles; float temperature; cout<<"Define T: "; cin>>temperature; if(pressure==0) cout<<"Pressure equals "<<(nofmoles*0.08206*temperature)/volume<<" atms."; if(volume==0) cout<<"Volume equals "<<(nofmoles*0.08206*temperature)/pressure<<" liters."; if(nofmoles==0) cout<<"Number of moles equals "<<(pressure*volume)/(0.08206*temperature)<<"."; if(temperature==0) cout<<"Temperature equals "<<(pressure*volume)/(0.08206*nofmoles)<<" degrees K."; cout<<" "; cout<<"Do you need to perform another conversion? "; cin>>question; }while(question==yes); return 0; }



LinkBack URL
About LinkBacks


