473,326 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Programming the volume of a sphere based on user input

heiro1
29
Hi guys!
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
  1. #include <iostream>
  2. using namespace std;
  3. // function main begins program execution
  4. int main()
  5. {
  6.     char userInput;
  7.     double r, v, sum, pi; // declared variables
  8.     pi=3.141593;
  9.     v=(4/3.0)*pi*r*r*r;
  10.     cout << "Please enter radius: ";  // prompt
  11.     cin >> r;                  // read an integer
  12.     sum = v;  // assign result to sum
  13.     cout << "Sum is " << sum << endl; // print sum
  14.     cout << "Press q to quit: ";
  15.     cin >> userInput;
  16.     return 0;   // indicate that program ended successfully
  17.     } // end function main
Jan 23 '13 #1
1 2287
heiro1
29
Woo-Hoo! I just figured it out (like a boss) lol, yea I know it is basic coding but hey, it is a milestone for me! :)

I'd post my result but wouldn't want future students to copy paste it. Thank you for looking anyway though!
Jan 24 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: N?ant Humain | last post by:
I have just begun learning Python so that I can write a simple script to make modification of a file used by another Python script easier. This file is basically a list of regular expressions. What...
2
by: reneeccwest | last post by:
Different user input boxes are automatically populated based on a value of the dropdown box. Can anyone help me on that?
2
by: Stan Cook | last post by:
How do you write a query which will stop ans wait for user input? Stan
5
by: SPEAKIT | last post by:
I'm sorry to ask what must be a very simple question, but I just can't seem to get this to work. Right now I am using the javascript 'prompt' to enter a photoid and the script that I am using uses...
7
by: Daniel Walzenbach | last post by:
Hello, I want to create a Word XML file based on the input users make in a VB.NET application. I imagine creating a template in Word and saving it as a XML file. I then want to fill the...
3
by: dei3cmix | last post by:
Hey, I am having a problem with a program I am working on. Basically, the first part of the program gets input from a file using cin.getline. Then the second part, (still in the same main as the...
4
by: joesin | last post by:
I recently found a vulnerability on my website that allowed sql injection. I have been trying to write some code that would clean user data but have been running into problems. The validation still...
14
by: n3o | last post by:
Hello Comp.Lang.C Members, I have an issue with user input that I have been trying to figure out for the longest. For instance, let's say you have something like this: void foo() { int num;...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
10
by: Shoaib Muhammad | last post by:
Hi every one, I am new in perl. I m using Active Perl 5.8.7 Window based. When i use <STDIN> for getting user input in my perl code, after executing i dont get any output on the screne. Following is...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.