User input/output

Any ways to do user input and output other than cin/cout

Page 1 of 1

1 Replies - 1530 Views - Last Post: 13 October 2008 - 02:18 PM Rate Topic: -----

#1 bbarker3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 12-October 08

User input/output

Post icon  Posted 13 October 2008 - 02:10 PM

I have my assignment finished, but is there any other option for user input and the outputs? (Simple first assignment. 1.Greet User. 2. Have user input radius in cm. 3. Inputs the radius. 4. Outputs the volume of the sphere.)

#include <stdio.h>
#include <iostream>
#include <math.h>

using namespace std;

int main(void)
{
	float sphereRadius;
	cout << "Welcome\n";
	cout << "Please enter a radius in cm: ";
	cin >> sphereRadius;
	cout << "The Volume of the sphere is \n" << (4 * 3.14159 * pow(sphereRadius, 3))/3 << "\n";
	return(0);

}


If possible, maybe go without having to use the #include <iostream>? I know for 'cout', I can just use printf("Welcome\n");, but anything I can differently with 'cin'?

Is This A Good Question/Topic? 0
  • +

Replies To: User input/output

#2 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: User input/output

Posted 13 October 2008 - 02:18 PM

Just as there's printf, there's a cin equivalent in scanf.

scanf("%i" , &i); <-- puts an integer into the variable i
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1