本文整理汇总了C++中GetFloat函数的典型用法代码示例。如果您正苦于以下问题:C++ GetFloat函数的具体用法?C++ GetFloat怎么用?C++ GetFloat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetFloat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (void)
{
// Get the size of the pizza from the user
printf("What's the diameter of the pizza? ");
float pizza_diameter = GetFloat();
// Calculate circumference and area of the pizza
float pizza_circumference = circumference(pizza_diameter);
float pizza_area = area( pizza_diameter / 2.0 );
// Tell the user all about their pizza
printf("The pizza is %f inches around.\n", pizza_circumference);
printf("The pizza has %f square inches.\n", pizza_area);
}
示例2: main
int main(void)
{
float amount;
do
{
printf("How much change is owed?\n");
amount = GetFloat();
}
while (amount < 0.0);
int amount_cents = to_cents(amount);
// Quarters
int type_coin = 25;
int total = num_coins(type_coin, amount_cents);
amount_cents = num_remain(type_coin, amount_cents);
// Dimes
type_coin = 10;
total = total + num_coins(type_coin, amount_cents);
amount_cents = num_remain(type_coin, amount_cents);
// Nickels
type_coin = 5;
total = total + num_coins(type_coin, amount_cents);
amount_cents = num_remain(type_coin, amount_cents);
// Pennies
type_coin = 1;
total = total + num_coins(type_coin, amount_cents);
amount_cents = num_remain(type_coin, amount_cents);
printf("Total: %d\n\n", total);
// Determine how many
// quarters
// dimes
// nickels
// pennies
// TODO
/*
- test large numbers 1.00039393
- test large ints
- test negative floats, ints
- test words
- words and ints
*/
}
示例3: main
int main(void)
{
float raw_change = 0;
do {
printf("how much change is due? ");
raw_change = GetFloat();
} while (raw_change < 0);
//printf("%f", change_due);
float change_due = raw_change;
float quarter_val = 0.25;
float dime_val = 0.10;
float nickel_val = 0.05;
float penny_val = 0.01;
int coin_count = 0;
while (change_due >= quarter_val) {
coin_count++;
change_due = (roundf(change_due * 100) - (quarter_val * 100)) / 100;
//printf("quarter test test = %f\n", roundf(change_due));
}
while (change_due >= dime_val) {
coin_count++;
change_due = (roundf(change_due * 100) - (dime_val * 100)) / 100;
//printf("dime test = %f\n", (change_due));
}
while (change_due >= nickel_val) {
coin_count++;
change_due = (roundf(change_due * 100) - (nickel_val * 100)) / 100;
//printf("nickel test = %f\n", (change_due));
}
while (change_due > 0) {
change_due = (roundf(change_due * 100) - (penny_val * 100)) / 100;
coin_count++;
//printf("penny test = %f\n", roundf(change_due));
}
printf("%d\n", coin_count);
//printf("change due is: %f\n", roundf(change_due));
}
示例4: main
int main(void)
{
// Prompt the user for change
float owed;
int counter = 0;
do
{
printf("Welcome to Greedy! How much change do you require?\n");
owed = GetFloat();
if (owed <= 0)
{
printf("You need to enter a positive number, please try again.\n");
}
}
while (owed <= 0);
int change = roundf ((owed * 100));
// calculate change
while (change >= 25)
{
change -= 25;
counter++;
}
while (change >= 10)
{
change -= 10;
counter++;
}
while (change >= 5)
{
change -= 5;
counter++;
}
while (change >= 1)
{
change -= 1;
counter++;
}
printf("%d\n", counter);
}
示例5: main
int main(void){
float change;
do {
printf("Change due:\n");
change = GetFloat();
} while(change < 0);
change = change * 100; // change from dollars
int newChange = (int) round(change); // float to int, round int
// finished getting change due
int coins = 0;
// do for 0.25
if(newChange >= 25){
do {
newChange = newChange - 25;
coins = coins + 1;
} while(newChange >= 25);
}
//
// do for 0.10
if(newChange >= 10){
do {
newChange = newChange - 10;
coins = coins + 1;
} while(newChange >= 10);
}
//
// do for 0.5
if(newChange >= 5){
do {
newChange = newChange - 5;
coins = coins + 1;
} while(newChange >= 5);
}
//
// do for 0.1
if(newChange >= 1){
do {
newChange = newChange - 1;
coins = coins + 1;
} while(newChange >= 1);
}
//
printf("%i\n", coins);
}
示例6: main
int main (void) {
// Declare variables.
float change;
int coin_counter = 0; // Must initialize here.
int change_int;
// Query user for amount of change.
do {
printf("How much change do you owe?\n");
change = GetFloat();
} while (change < 0.00);
// Calculate the number of coins needed to fulfill the request.
// First, round the change to an integer value. Using math library for round fxn.
change_int = round(change * 100);
/* Calculate number of coins. Algorithm takes value, subtracts chunks of coin values, and checks to see whether or not one can still use
that type of coin with a while loop check. */
// Begin with quarters.
while (change_int >= 25) {
change_int -= 25;
coin_counter += 1;
}
// Then sort out dimes.
while (change_int >= 10) {
change_int -= 10;
coin_counter += 1;
}
// Then nickels.
while (change_int >= 5) {
change_int -= 5;
coin_counter += 1;
}
// And lastly, cents.
while (change_int >= 1) {
change_int -= 1;
coin_counter += 1;
}
// Print the result.
printf("%i\n", coin_counter);
// Return null if error present.
return 0;
}
示例7: main
int main(void)
{
// get correct input from user
float change;
do
{
printf("How much change is owed?\n");
change = GetFloat();
}
while(change <= 0);
// change into...
int coins = 0;
// quarters...
while(change >= 0.25)
{
change = change - 0.25;
coins++;
}
change = (round(change * 100)/100);
// dimes...
while(change >= 0.1)
{
change = change - 0.1;
coins++;
}
change = (round(change * 100)/100);
// nickels
while(change >= 0.05)
{
change = change - 0.05;
coins++;
}
change = (round(change * 100)/100);
// and pennys
while(change >= 0.009)
{
change = change - 0.01;
coins++;
}
change = (round(change * 100)/100);
// print result
printf("%i\n", coins);
}
示例8: assert
bool CBasePoly::LoadBasePolyLTA( CLTANode* pNode )
{
// CLTANode* pIndicesNode = pNode->getElem(0); // shallow_find_list(pNode, "indices");
CLTANode* pIndex = pNode->GetElement(1); //PairCdrNode(pIndicesNode);
uint32 listSize = pIndex->GetNumElements();
assert(listSize > 0);
m_Indices.SetSize( listSize - 1 );
for( uint32 i = 1; i < listSize; i++ )
{
Index(i-1) = GetUint32(pIndex->GetElement(i));
if( Index(i-1) >= m_pBrush->m_Points )
{
Index(i-1) = 0;
return false;
}
}
CLTANode* pNormalNode = pNode->GetElement(2); //shallow_find_list(pNode, "normal");
if( pNormalNode )
{
Normal().x = GetFloat(pNormalNode->GetElement(1));
Normal().y = GetFloat(pNormalNode->GetElement(2));
Normal().z = GetFloat(pNormalNode->GetElement(3));
}
CLTANode* pDistNode = pNode->GetElement(3); //shallow_find_list(pNode, "dist");
if( pDistNode )
{
Dist() = GetFloat(PairCdrNode(pDistNode));
}
return true;
}
示例9: GetCode
//-----------------------------------------------------------------------------------------------
string_type Variable::AsciiDump() const
{
stringstream_type ss;
ss << g_sCmdCode[ GetCode() ];
ss << _T(" [addr=0x") << std::hex << this << std::dec;
ss << _T("; pos=") << GetExprPos();
ss << _T("; id=\"") << GetIdent() << _T("\"");
ss << _T("; type=\"") << GetType() << _T("\"");
ss << _T("; val=");
switch(GetType())
{
case 'i': ss << (int_type)GetFloat(); break;
case 'f': ss << GetFloat(); break;
case 'm': ss << _T("(array)"); break;
case 's': ss << _T("\"") << GetString() << _T("\""); break;
}
ss << ((IsFlagSet(IToken::flVOLATILE)) ? _T("; ") : _T("; not ")) << _T("vol");
ss << _T("]");
return ss.str();
}
示例10: GetToken
void cAseLoader::ProcessMESH_TVERTLIST( OUT std::vector<D3DXVECTOR2>& vecVT )
{
int nLevel = 0;
do
{
char* szToken = GetToken();
if(IsEqual(szToken, "{"))
{
++nLevel;
}
else if(IsEqual(szToken, "}"))
{
--nLevel;
}
else if(IsEqual(szToken, ID_MESH_TVERT))
{
int nIndex = GetInteger();
vecVT[nIndex].x = GetFloat();
vecVT[nIndex].y = 1.0f - GetFloat();
}
} while (nLevel > 0);
}
示例11: GetSfx
LRESULT KGSFXGlobPage::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
IEKG3DSFX* sfx = GetSfx();
switch (message)
{
case WM_EDIT_RECEIVE_ENTER :
{
switch (wParam)
{
case IDC_EDIT_MAX_NUM :
{
if (GetInt(lParam) < 0)
break;
if (sfx)
sfx->SetMaxParticleNum(GetInt(lParam));
}
break;
case IDC_EDIT_WAVE_POWER :
{
if (GetFloat(lParam) < 0)
break;
if (sfx)
sfx->SetShockWavePower(GetFloat(lParam));
}
break;
default :
break;
}
}
break;
default :
break;
}
return CDialog::WindowProc(message, wParam, lParam);
}
示例12: GetFloat
float WBEvent::SParameter::CoerceFloat() const
{
if( m_Type == EWBEPT_Float )
{
return GetFloat();
}
else if( m_Type == EWBEPT_Int )
{
return static_cast<float>( GetInt() );
}
else
{
return 0.0f;
}
}
示例13: main
int main(void)
{
printf("O hai! ");
// Retrieve change owed
float owed = -1.0;
while ( owed < 0 )
{
printf("How much change is owed?\n");
owed = GetFloat();
}
// Convert a floating point dollar to a cent integer
int cents_owed = (int) round(owed * 100);
int coins = 0;
// Count out quarters
while ( cents_owed >= 25 )
{
cents_owed = cents_owed - 25;
coins++;
}
// Count out dimes
while ( cents_owed >= 10 )
{
cents_owed = cents_owed - 10;
coins++;
}
// Count out nickels
while ( cents_owed >= 5 )
{
cents_owed = cents_owed - 5;
coins++;
}
// Count out pennies
while ( cents_owed >= 1 )
{
cents_owed = cents_owed - 1;
coins++;
}
// Print final coin count
printf("%i\n", coins);
}
示例14: spec
nsresult
nsSMILParserUtils::ParseRepeatCount(const nsAString& aSpec,
nsSMILRepeatCount& aResult)
{
nsresult rv = NS_OK;
NS_ConvertUTF16toUTF8 spec(aSpec);
nsACString::const_iterator start, end;
spec.BeginReading(start);
spec.EndReading(end);
SkipWsp(start, end);
if (start != end)
{
if (ConsumeSubstring(start, end, "indefinite")) {
aResult.SetIndefinite();
} else {
double value = GetFloat(start, end, &rv);
if (NS_SUCCEEDED(rv))
{
/* Repeat counts must be > 0 */
if (value <= 0.0) {
rv = NS_ERROR_FAILURE;
} else {
aResult = value;
}
}
}
/* Check for trailing junk */
SkipWsp(start, end);
if (start != end) {
rv = NS_ERROR_FAILURE;
}
} else {
/* Empty spec */
rv = NS_ERROR_FAILURE;
}
if (NS_FAILED(rv)) {
aResult.Unset();
}
return rv;
}
示例15: main
int main(void)
{
const int CENTS_IN_DOLLAR = 100;
// say hi!
printf("O hai! ");
float change_reqd;
// get amount of change from the user, ensuring it is positive
do
{
printf("How much change is owed?\n");
change_reqd = GetFloat();
}
while (change_reqd < 0);
// convert from dollars to cents
int change_in_cents = round(change_reqd * CENTS_IN_DOLLAR);
int coins_owed = 0;
// while we still have change left to calculate
while (change_in_cents > 0)
{
if (change_in_cents >= 25)
{
change_in_cents -= 25;
}
else if (change_in_cents >= 10)
{
change_in_cents -= 10;
}
else if (change_in_cents >= 5)
{
change_in_cents -= 5;
}
else
{
change_in_cents--;
}
// increment the number of coins owed
coins_owed++;
}
// output the number of coins owed
printf("%i\n", coins_owed);
}