I've almost got it working in a different calculator. It follows a similar trend.
Code:
#include <iostream>
using namespace std;
int main(){
const double mol = 1.0;
const double gas_const = 8.315;
double pres1;
double pres2;
double vol;
double temp;
char choice1 = 0;
while( choice1 != 'y'){
cout << "\n Do you wish to enter a temperature and volume? ([Y]es or [N]o)" << endl;
char choice1;
cin >> choice1;
switch (choice1){
case 'y':
case 'Y':
cout << "\n Is the temperature in [K]elvin or [C]elsius?" << endl;
char choice2;
cin >> choice2;
switch (choice2){
case 'k':
case 'K':
cout << "\n Please enter the temperature (K)." << endl;
cin >> temp;
cout << "\n Please enter the volume (m^3)." << endl;
cin >> vol;
pres1 = (mol * gas_const * temp) / vol;
cout << "\n One mole of gas at " << temp << "K, in a volume of " << vol << "m^3, has a pressure of " << pres1 << "J." << endl;
break;
case 'c':
case 'C':
cout << "\n Please enter the temperature (C)." << endl;
cin >> temp;
cout << "\n Please enter the volume (m^3)." << endl;
cin >> vol;
pres2 = (mol * gas_const * (temp + 273)) / vol;
cout << "\n One mole of gas at " << temp << "C, in a volume of " << vol << "m^3, has a pressure of " << pres2 << "J." << endl;
}
break;
case 'n':
case 'N':;
}
}
cout << "Thank you for using my ideal gas pressure calculator." << endl;
}
If I enter y or Y, I go through the loop of entering variables and choosing units. If I enter n or N, it repeats the first question. I haven't worked out how to break the loop and get the final comment if I enter n or N.