本文整理汇总了C++中GetFloat函数的典型用法代码示例。如果您正苦于以下问题:C++ GetFloat函数的具体用法?C++ GetFloat怎么用?C++ GetFloat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetFloat函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:LaunchCodeEducation,项目名称:cs50x-kansascity,代码行数:14,代码来源:pizza-3.c
示例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
*/
}
开发者ID:schmidtg,项目名称:classwork,代码行数:49,代码来源:greedy.c
示例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));
}
开发者ID:Jonnokc,项目名称:cs50,代码行数:49,代码来源:greedy.c
示例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);
}
开发者ID:Japloe,项目名称:CS50_PSET1,代码行数:49,代码来源:greedy.c
示例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);
}
开发者ID:Rob--,项目名称:CS50,代码行数:49,代码来源:greedy.c
示例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;
}
开发者ID:kamil-krawczyk,项目名称:CS50-Homework,代码行数:49,代码来源:greedy.c
示例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);
}
开发者ID:barryonthehub,项目名称:exercises,代码行数:49,代码来源:greedy.c
示例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;
}
开发者ID:Joincheng,项目名称:lithtech,代码行数:36,代码来源:BasePoly.cpp
示例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();
}
开发者ID:cloudqiu1110,项目名称:math-parser-benchmark-project,代码行数:25,代码来源:mpVariable.cpp
示例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);
}
开发者ID:gawallsibya,项目名称:SGA_Direct3D,代码行数:24,代码来源:cAseLoader.cpp
示例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);
}
开发者ID:viticm,项目名称:pap2,代码行数:36,代码来源:KGSFXGlobPage.cpp
示例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;
}
}
开发者ID:MinorKeyGames,项目名称:Eldritch,代码行数:15,代码来源:wbevent.cpp
示例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);
}
开发者ID:mookie-blaylocks,项目名称:cs50,代码行数:48,代码来源:greedy.c
示例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;
}
开发者ID:AllenDou,项目名称:firefox,代码行数:48,代码来源:nsSMILParserUtils.cpp
示例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);
}
开发者ID:sycrat,项目名称:cs50,代码行数:48,代码来源:greedy.c
示例16: main
int main (void)
{
//Variables
float amount = 0;
int cents = 0;
int quartercount = 0;
int dimecount = 0;
int nickelcount = 0;
int pennies = 0;
int coincount = 0;
do
{
printf("Input a float valor (0.00): ");
amount = GetFloat();
}
while(amount <= 0);
// amount is convert to cents
cents = (int)round(amount*100);
// Quarters
quartercount = cents / 25;
pennies = cents % 25;
// Dimes
dimecount = pennies / 10;
pennies = pennies % 10;
// Nickels
nickelcount = pennies / 5;
pennies = pennies % 5;
// Pennies
coincount = quartercount + dimecount + nickelcount + pennies;
//condition for plural
char string[] = "s";
if (coins = 1 || quarters = 1 || dimes= 1 || nickels = 1 || pennies = 1)
{
// printing result of count coins
printf("You will get %d coin%s: %d quarter%s, %d dime%s, %d nickel%s and %d pennie%s.\n",
coincount, quartercount, dimecount, nickelcount, pennies, string);
}
return 0;
}
开发者ID:fulvi0,项目名称:cs50_homework,代码行数:48,代码来源:ifesleif.c
示例17: GetTheme
void g2Spinner::Render(int pX, int pY)
{
// Source texture coordinates for spinner
float SourceX, SourceY, SourceWidth, SourceHeight;
int OutWidth, OutHeight;
GetTheme()->GetComponent(g2Theme_Spinner_Pressed, &SourceX, &SourceY, &SourceWidth, &SourceHeight, &OutWidth, &OutHeight);
// Compute the offsets based on the size of the text field
int OffsetX = TextField->GetWidth();
int OffsetY = 0;
GetTheme()->GetComponentSize(g2Theme_TextField, NULL, &OffsetY);
OffsetY = OffsetY / 2 - OutHeight / 2; // Centered vertically
// Is the user's mouse on the top or bottom of the button?
// Note the ternary comparison operator to do the half-height offset
bool IsAbove = (MouseY < (OffsetY + (OutHeight / 2)));
bool IsVerticalBound = (MouseY >= OffsetY && MouseY <= (OffsetY + OutHeight));
// Disabled
if(GetDisabled())
DrawComponent(g2Theme_Spinner_Disabled, pX + OffsetX, pY + OffsetY);
// Actively pressed on the buttons, need to draw only the pressed button
else if( ((ControllerState & g2ControllerState_Pressed) == g2ControllerState_Pressed) && MouseX > TextField->GetWidth() && IsVerticalBound )
{
// Draw background normally, then draw the pressed button
DrawComponent(g2Theme_Spinner, pX + OffsetX, pY + OffsetY);
DrawComponent(pX + OffsetX, pY + OffsetY + (IsAbove ? 0 : (OutHeight / 2)), OutWidth, OutHeight / 2, SourceX, SourceY + (SourceHeight / 2.0f) * (IsAbove ? 0.0f : 1.0f), SourceWidth, SourceHeight / 2.0f);
}
// Normal
else
DrawComponent(g2Theme_Spinner, pX + OffsetX, pY + OffsetY);
// Increase or decrease the value based on timing
if((PressedTime > (g2Spinner_UpdateRate + g2Spinner_UpdateMin)) || (((ControllerState & g2ControllerState_Clicked) == g2ControllerState_Clicked) && MouseX > TextField->GetWidth() && IsVerticalBound))
{
if(IsAbove)
IncrementUp();
else
IncrementDown();
PressedTime -= g2Spinner_UpdateRate;
}
// Set the live value based on what the field currently has
if(LiveValue != NULL)
*LiveValue = (Type == g2SpinnerType_Float) ? GetFloat() : (float)GetInt();
}
开发者ID:blast007,项目名称:glui2,代码行数:48,代码来源:g2Spinner.cpp
示例18: main
int main(void)
{
// Variable declarations
float given_amount = 0;
int cent_amount = 0;
int quarter_count = 0;
int dime_count = 0;
int nickel_count = 0;
int leftover = 0;
int coin_count = 0;
//Input handling
do
{
printf("You gave me: ");
given_amount = GetFloat();
//If given amount is zero or less then zero checked
if(given_amount == 0||given_amount <= 0)
printf("Number Should be greater then Zero EG:10\n:");
}
while(given_amount <= 0);
// Given amount is convert to cents
cent_amount = (int)round(given_amount*100);
// Quarters
quarter_count = cent_amount / QUARTER;
leftover = cent_amount % QUARTER;
// Dimes
dime_count = leftover / DIME;
leftover = leftover % DIME;
// Nickels
nickel_count = leftover / NICKEL;
leftover = leftover % NICKEL;
// Leftover at this stage is pennies
coin_count = quarter_count + dime_count + nickel_count + leftover;
// Pretty print
// printf("You get %d coins: %d quarters, %d dimes, %d nickels and %d pennies.\n", coin_count, quarter_count, dime_count, nickel_count, leftover);
//Required output:
printf("%d\n", coin_count);
return 0;
}
开发者ID:Javs42,项目名称:cs50,代码行数:48,代码来源:greedy.c
示例19: GetType
std::string BaseRowsetReader::iterator::GetAsString( size_t index ) const
{
const PyRep::PyType t = GetType( index );
switch( t )
{
case PyRep::PyTypeNone:
return "NULL";
case PyRep::PyTypeBool:
return itoa( GetBool( index ) ? 1 : 0 );
case PyRep::PyTypeInt:
return itoa( GetInt( index ) );
case PyRep::PyTypeLong:
return itoa( GetLong( index ) );
case PyRep::PyTypeFloat:
{
char buf[64];
snprintf( buf, 64, "%f", GetFloat( index ) );
return buf;
}
case PyRep::PyTypeString:
{
std::string str = GetString( index );
EscapeString( str, "'", "\\'" );
str.insert( str.begin(), '\'' );
str.insert( str.end(), '\'' );
return str;
}
case PyRep::PyTypeWString:
{
std::string str = GetWString( index );
EscapeString( str, "'", "\\'" );
str.insert( str.begin(), '\'' );
str.insert( str.end(), '\'' );
return str;
}
default:
{
char buf[64];
snprintf( buf, 64, "'UNKNOWN TYPE %u'", t );
return buf;
}
}
}
开发者ID:AlTahir,项目名称:Apocrypha_combo,代码行数:48,代码来源:RowsetReader.cpp
示例20: GetInt
void cFishShowProbability::ProcessFishesShowProbabilityData(TiXmlElement*e_pTiXmlElement)
{
m_FishesShowProbability.FishAndProbabilityVector.clear();
m_FishesShowProbability.iAppearFishesCount = GetInt(e_pTiXmlElement->Attribute(L"AppearFishTypeCount"));
m_FishesShowProbability.vFishShowRange = GetVector2(e_pTiXmlElement->Attribute(L"FishShowRange"));
e_pTiXmlElement = e_pTiXmlElement->FirstChildElement();
while( e_pTiXmlElement )
{
std::wstring l_strFileName = e_pTiXmlElement->Attribute(L"FileName");
float l_fProbability = GetFloat(e_pTiXmlElement->Attribute(L"Probability"));
WCHAR l_wcShowAreaID = e_pTiXmlElement->Attribute(L"AreaID")[0];
sFishAndProbability l_sFishAndProbability(l_strFileName,l_fProbability,l_wcShowAreaID);
m_FishesShowProbability.FishAndProbabilityVector.push_back(l_sFishAndProbability);
e_pTiXmlElement = e_pTiXmlElement->NextSiblingElement();
}
}
开发者ID:fatmingwang,项目名称:FM79979,代码行数:16,代码来源:FishShowProbability.cpp
注:本文中的GetFloat函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论