Code:
#include <iostream>
using namespace std;
//Global Values are bad and you shouldn't use them
//I'm using them b/c it is easyer to help you understand what I've done.
const double mol = 1.0;
const double gas_const = 8.315;
double pres1;
double pres2;
double vol;
double temp;
//I have moved your caculation code to its own function to help clarifity your main loop.
void Calculate(){ //sorry for my spelling.
//Please note that one tab has been placed to denote your inside a function.
cout << "\n Is the temperature in [K]elvin or [C]elsius?" << endl;
char choice2;
cin >> choice2;
switch (choice2){
//Please note that another tab has been added to denote the switch statement
case 'k':
case 'K':
//And another tab has been added to show you have entered a logic sequence.
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;
//As you exit the logic sequence you subtract a tab space.
break;
case 'c':
case 'C':
//Added another tab for the logic sequence
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;
//Deleted the tab as we exit this logic sequence.
break;
}
}
int main(){
char choice1 = 0; //Please remimber this line.
while( choice1 != 'n'){
cout << "\n Do you wish to enter a temperature and volume? ([Y]es or [N]o)" << endl;
char choice1; //Please look at line 53, this is why you can not exit your program.
cin >> choice1;
switch (choice1){
case 'y':
case 'Y':
Calculate();
case 'n':
case 'N':;
}
}
cout << "Thank you for using my ideal gas pressure calculator." << endl;
}