5 Replies - 456 Views - Last Post: 21 August 2009 - 09:59 PM Rate Topic: -----

#1 vwyodapink  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 141
  • Joined: 12-May 09

First Program since the beginning of class I did

Post icon  Posted 21 August 2009 - 07:58 PM

Just wanted to share I actually did one whole program on my own and figured out everything with no assitance. Of course its a way basic program but maybe things are finally starting to click somewhat again. Thanks as always everyone !!!

#include <iostream>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;
using std::setprecision;
using std::fixed;

//function prototypes
void getFahrenheit(int &);
void calcCelsius(double &, int &);
void displayCelsius(double &);

int main()
{	
	//declare variables
	int fahrenheit = 0;
	double celsius = 0.0;
	
	//get input item
	getFahrenheit(fahrenheit);
	
	//calculate Celsius
	calcCelsius(celsius, fahrenheit);

	//display output item
	displayCelsius(celsius);

	return 0;
}   //end of main function

//*****function definitions*****
void getFahrenheit(int &fahrenheit)
{
	cout << "Enter the temperature in Fahrenheit you would like converted to Celsius: " << endl;
		cin >> fahrenheit;
}

void calcCelsius(double &celsius, int &fahrenheit)
{
	celsius = 5.0/9.0 * (fahrenheit - 32.0);
}

void displayCelsius(double &celsius)
{
	cout << fixed << setprecision(0) << "Your converted temperature is: " << celsius << " degrees" << endl;
}



Is This A Good Question/Topic? 0
  • +

Replies To: First Program since the beginning of class I did

#2 Ancient Dragon  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 81
  • View blog
  • Posts: 679
  • Joined: 19-July 09

Re: First Program since the beginning of class I did

Posted 21 August 2009 - 08:08 PM

View Postvwyodapink, on 21 Aug, 2009 - 06:58 PM, said:

Just wanted to share I actually did one whole program on my own and figured out everything with no assitance.



Congratulations -- Great Job :^:
Was This Post Helpful? 0
  • +
  • -

#3 vwyodapink  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 141
  • Joined: 12-May 09

Re: First Program since the beginning of class I did

Posted 21 August 2009 - 08:17 PM

BAM!!! Two in a row .. Better not gloat to much I am on to a new Chapter lol

#include <iostream>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;
using std::setprecision;
using std::fixed;

//function prototypes
void getSales(double &);
void calcBonus(double &, double &, const double);
void displayBonus(double &);

int main()
{	
	  //declare constant and variables
	const double RATE = .1;
	double sales = 0.0;
	double bonus = 0.0;
	
	//get input item
	getSales(sales);
	
	//calculate bonus
	calcBonus(bonus, sales, RATE);

	//display output item
	displayBonus(bonus);

	return 0;
}   //end of main function

//*****function definitions*****
void getSales(double &sales)
{
	cout << "Enter your total sales: ";
	cin >> sales;
}

void calcBonus(double &bonus, double &sales, const double RATE)
{
	bonus = sales * RATE;
}

void displayBonus(double &bonus)
{
	cout << fixed << setprecision(2) << "Your total bonus is $" << bonus << endl;
}


Was This Post Helpful? 0
  • +
  • -

#4 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 73
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: First Program since the beginning of class I did

Posted 21 August 2009 - 08:47 PM

Would've been easier just to type using namespace std; at the top instead of all that.
Was This Post Helpful? 0
  • +
  • -

#5 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: First Program since the beginning of class I did

Posted 21 August 2009 - 09:33 PM

View Postvwyodapink, on 21 Aug, 2009 - 09:58 PM, said:

Just wanted to share I actually did one whole program on my own and figured out everything with no assitance.


:w00t: Awesome! :genius: :bananaman:
Was This Post Helpful? 0
  • +
  • -

#6 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: First Program since the beginning of class I did

Posted 21 August 2009 - 09:59 PM

View PostSarumanTheWhite, on 21 Aug, 2009 - 10:47 PM, said:

Would've been easier just to type using namespace std; at the top instead of all that.


it is actually better to use this method -- and many IDE's will automatically generate the "using whatever" lines for you so it is not like it has to be any extra work.

When you add "using namespace std;" you are cramming in the entire namespace -- do you know the name of every symbol in std? I certainly don't.

For beginner programs it is ok to use the shortcut -- but when your programs get larger and begin to span multiple namespaces and you are using other libraries -- this is just not a good idea.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1