I apologize in advance for the extremely noob queston but I am guessing it should be a snap for anyone to point me in the correct direction.
Essentially, I am stuck because I do not know how to generate a line of code that allows someone to add a value of their choice for r(in this case would be their input for a radius value) and have that value calculated based on volume parameters I have coded in.
So, mainly my problem is that I need to initialize r as a variable that the user types in at a prompt. If you notice any errors I have made please point them out as well. I know this code is incomplete but if I at least have a better understanding I can get the perverbial ball rolling.
It would just be more helpful if this made more sense to me because the textbook is not helpful to me at all : / Thank you so much for your time!
Here is what I have so far:
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- using namespace std;
- // function main begins program execution
- int main()
- {
- char userInput;
- double r, v, sum, pi; // declared variables
- pi=3.141593;
- v=(4/3.0)*pi*r*r*r;
- cout << "Please enter radius: "; // prompt
- cin >> r; // read an integer
- sum = v; // assign result to sum
- cout << "Sum is " << sum << endl; // print sum
- cout << "Press q to quit: ";
- cin >> userInput;
- return 0; // indicate that program ended successfully
- } // end function main