|
Newbie
Join Date: Mar 2006
Location: Tj, Mx
Posts: 7
Rep Power: 0 
|
double functions (getting weird numbers)
Hi, I was wondering if someone could check my C++ code to see if can figure out why when I run my program I get sme weird numbers(3.123445ADD. I know that something is wrong with my functions but can't figure out what is it, I would really appreciate any help, here is what I have.
#include <iostream>
#include <string> //Needed for string variables
#include <windows.h> //To have Colors
#include <cmath> //Needed for ceil() & floor()
#include <iomanip> //Needed for setw()
using namespace std;
void welcome();
//A message to greet user
void hitEnter();
//Prompt user to hit ENTER key in order to continue
void logo();
//My logo JB will display to id my work
string getUserName();
//Prompt user for name and return the name
void order();
void echoInfo( string userName );
void obtainSizeAndPrice( string userName, int& size, int& price );
void echoInfo( string userName, int size, int price );
double getAreaOfPizza( double P_I, int size );
double calculatePizzaPrice( double areaOfPizza, int price );
double round( double pizzaCost );
void niceFormat();
int main()
{
//User defined function calls
welcome();
logo();
order();
return(0);
}
/**********************************************************
***********************************************************
FUNCTION DECLARATIONS
***********************************************************
**********************************************************/
/**********************************************************
***********************************************************
hitEnter prompt user to hit enter in order to continue
***********************************************************
**********************************************************/
void hitEnter()
{
cout << "\n\n\t\t\t*** Hit ENTER to continue ****\n";
cin.ignore();
return;
}
/**********************************************************
***********************************************************
Order
***********************************************************
**********************************************************/
void order()
{
const double P_I = 3.14159;
string userName;
int size,
price;
double areaOfPizza,
pizzaCost,
roundFloor,
roundPizza;
userName = getUserName();
echoInfo ( userName );
obtainSizeAndPrice( userName, size, price );
echoInfo( userName, size, price );
cout << "\n\n\nSince a " <<size << "-inch pizza covers ";
areaOfPizza = getAreaOfPizza( P_I, size );
cout << areaOfPizza <<
cout << " square inches, then at " << price<< " cents per square\n";
cout << "inch, the cost is $";
niceFormat();
pizzaCost = calculatePizzaPrice( areaOfPizza, price );
cout << pizzaCost<<
cout << ". This rounds to $";
roundPizza = round( pizzaCost );
cout << roundPizza<<
cout <<"\n\n";
cin.ignore();
}
/**********************************************************
***********************************************************
GetUserName ask for username and stores it
***********************************************************
**********************************************************/
string getUserName()
{
string name;
cout << "\n\nPlease enter your first name and hit ENTER: ";
cin >> name;
return name;
}
/**********************************************************
***********************************************************
echoInfo returns the name of user.
***********************************************************
**********************************************************/
void echoInfo( string userName )
{
cout << "\n\n\t Ah, " <<userName << ", so nice to have you joining us";
cout << " today for some pizza!!\n\n\n";
hitEnter();
cin.ignore();
system( "cls" );
return;
}
/**********************************************************
***********************************************************
obtainSizeAndPrice ask user for size and price
**********************************************************
**********************************************************/
void obtainSizeAndPrice( string userName, int& size, int& price )
{
cout <<"\n\n\n "<<userName << ", please enter the pizza size (5 - 25 inches in diameter),";
cout << " and price \n";
cout << "of ingredients (10 - 15 cents per square inch of pizza), like 5 10: ";
cin >> size >> price;
return;
}
/**********************************************************
***********************************************************
echoInfo display info given by user
***********************************************************
**********************************************************/
void echoInfo( string userName, int size, int price )
{
cout << "\n\n\nThanks, " <<userName << ", for selecting a " <<size << "-inch pizza at ";
cout <<price << " cents per square inch.\n";
hitEnter();
cin.ignore();
system( "cls" );
return;
}
void niceFormat()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
return;
}
double getAreaOfPizza( double P_I, int size )
{
return (P_I*(size/2)*(size/2));
}
double calculatePizzaPrice( double areaOfPizza, int price )
{
return ((areaOfPizza*price)/100);
}
double round( double pizzaCost )
{
return (floor(pizzaCost + 0.5));
}
What's wrong ?? I have been here for a couple of hours and nothing. help please!!!
|