c++ help

need code for c++ minimum number and volume of a shape

Page 1 of 1

3 Replies - 827 Views - Last Post: 15 October 2008 - 04:31 PM Rate Topic: -----

#1 bkozminski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-October 08

c++ help

Posted 15 October 2008 - 03:30 PM

Can someone help me with code for c++ beginners stuff.

I need the code for finding the minimum number and another code for finding the volume of a cylinder..

Thanks!

#include <iostream>
using namespace std;
void main() {
int num = 0;
int num1 = 0;
int num2 = 0;
int num3 = 0;
cout << "Please enter three numbers between 0-3" << endl;
cin >> num1 >> num2 << num3;
num = abs(num1);
if (num1 == 0) {
	cout << "The number you entered is the minimum number because you entered zero!" << endl;}
else if  (num1 ,3){
	cout << "The number  " << num1 << "	" << num << endl;}
else if (num1 >0) {
	cout << "The number  " << num1 << " is a positive and its absolute value is   " << num << endl;}


Mod edit - Please :code:
~BetaWar

Is This A Good Question/Topic? 0
  • +

Replies To: c++ help

#2 rtokars  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 20
  • Joined: 18-July 08

Re: c++ help

Posted 15 October 2008 - 03:52 PM

if you have 3 numbers and want to find the minimum and volume you could use something as simple as:
int min;
int volume = num1*num2*num3;
if ((num1<num2)&&(num1<num3))
	min = num1;
else if ((num2<num1)&&(num2<num3))
	min = num2;
else
	min = num3;



this code assumes you have already initialized num1 num2 num3.

This post has been edited by rtokars: 15 October 2008 - 03:54 PM

Was This Post Helpful? 0
  • +
  • -

#3 F!st!cuffs  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 153
  • Joined: 15-July 08

Re: c++ help

Posted 15 October 2008 - 04:10 PM

When your trying to find the minimum you could use an array and a loop. With just three numbers rtokars way works fine but if you scale it up your gonna need alot of if else statements.
assuming you already have a populated array the loop would look like this
int minimum = array[0];
for ( int i = 0; i < arrayLength; i++ ){
    if ( array[i] < minimum ){
        minimum = array[i];
    }
}
// if you use this in a function then return minimum


As for volume "Determine the volume of a cylinder by first multiplying the square of the radius by pi. Multiply this product by the cylinder's height. Example: The volume of a cylinder with radius 3 and height 5 is pi x 3 x 3 x 5 = 141."
Was This Post Helpful? 0
  • +
  • -

#4 fountainoftruth  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 04-December 07

Re: c++ help

Posted 15 October 2008 - 04:31 PM

This
cin >> num1 >> num2 << num3;


should be
cin >> num1 >> num2 >> num3;



Slight mix up, but I'm sure it's something that would make you feel dumb later for not catching it earlier. I've done similar things more times than I could count.

For the volume, create a function
double volume(int radius, int height) {
//calculations
}


that will calculate the volume of the cylinder. If you have troubles, post the code you made for it.

This post has been edited by fountainoftruth: 15 October 2008 - 04:31 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1