Hello.
I'm new to C Programming and am struggling with a practice exercise for a course I'm doing. My aim is to code a simple calculator, which has two constants, two variables that are manually input, and an answer. Then there is a statement at the end showing my two input values and the answer to the calculation.
I just don't know how to get this to work.
The calculator uses the expression P = nRT/V, where n and R are constants that I define in the program, and T and V are variables that I input manually.Code:#include <iostream> using namespace std; int main () { //variable declarations and initialisation const double mol = 1.0; const double gas_const = 8.315; char temp[50], vol[50], pres[50]; //prompt and read cout << "Please enter the temperature / K:" << endl; cin >> temp; cout << "Please enter the volume / m^3:" << endl; cin >> vol; //calculate pressure pres = (mol * gas_const * temp) / vol; //print result cout << "One mole of gas at " << temp << "K, in a volume of " << vol << "m^3, has a pressure of " << pres << "Pa." << endl; } //end of main()
This coding gives a single error on the line with the equation:
Both "pres" and "temp" have red lines underneath. When I move the cursor over "pres" I get "Error: expression must be a modifyable lvalue", and doing the same with "temp" gives "Error: expression must have arithmetic or enum type".Code:error C2297: '*' : illegal, right operand has type 'char [50]'
I've been working on this for almost four hours at the time of posting. I've Googled and searched through books, I've gone through my notes, but I don't understand what I'm supposed to do.
If I remove the expression and give "pres" a fixed value, the statement at the end works. Its the expression part that I don't understand.
Could anyone help me with this? Any help would be very much appreciated.
Thanks.



LinkBack URL
About LinkBacks



