# First Program since the beginning of class I did

Page 1 of 1

## 5 Replies - 652 Views - Last Post: 21 August 2009 - 09:59 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=121631&amp;s=e9ecf820b43bbeb25c43a98c45cdb3dc&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 vwyodapink

• D.I.C Head

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

# First Program since the beginning of class I did

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

• D.I.C Addict

Reputation: 82
• Posts: 679
• Joined: 19-July 09

## Re: First Program since the beginning of class I did

Posted 21 August 2009 - 08:08 PM

vwyodapink, 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

• D.I.C Head

Reputation: 2
• 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

• D.I.C Regular

Reputation: 74
• 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

• Everybody's crazy but me!

Reputation: 135
• Posts: 6,581
• Joined: 11-July 07

## Re: First Program since the beginning of class I did

Posted 21 August 2009 - 09:33 PM

vwyodapink, 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.

Awesome!
Was This Post Helpful? 0

### #6 NickDMax

• Can grep dead trees!

Reputation: 2254
• Posts: 9,245
• Joined: 18-February 07

## Re: First Program since the beginning of class I did

Posted 21 August 2009 - 09:59 PM

SarumanTheWhite, 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

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}