Is that not what you said you wanted before?
If not, then you need to specify exactly how you intend your program to work.
Printable View
Is that not what you said you wanted before?
If not, then you need to specify exactly how you intend your program to work.
Sorry. I'm starting to get confused now.
If I choose to enter values, I go through the process of entering them and calculating the answer. Once I've done that I'm asked again to enter values. If I choose not to enter anything, I'm supposed to get the thank you message and no more questions, effectively ending the program.
I'd just like to thank you for your patience with me. You've been a great help, and I'm learning alot from you. :o
Right.
Well, look at your logic right now.
It's currently:
You probably want:Code:While user wants to input values
Do you want to enter values? [Y/N]
Ask for values
Calculate
Loop
Code:While user wants to input values
Ask for values
Calculate
Do you want to enter values? [Y/N]
Loop
The instructions I have say I need to start with the question.
Its late here, so I'll have to pick this up tomorrow. Thanks again for all your help, and take care. :o
There are many ways to formulate logic. Another version might be:
Code:While user wants to input values
Do you want to enter values? [Y/N]
If user wants to enter values
Ask for values
Calculate
Loop
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;
}
Hi
Sorry I didn't get back sooner. I've been really busy/distracted.
I didn't manage to get the pressure calculation working until Nor's code, so thank you for that. I did however manage to get the main assessment done using Elysia's help, so thank you for that. I got 100% of the marks.
You've both been a great help, and I've learned alot.
Thank you very much.
Well done. That's great.