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);
}
Beispiel #2
0
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
    */
}
Beispiel #3
0
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));



}
Beispiel #4
0
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);
}
Beispiel #5
0
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); 
}
Beispiel #6
0
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;
}
Beispiel #7
0
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);
}
Beispiel #8
0
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;
}
  //-----------------------------------------------------------------------------------------------
  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();
  }
Beispiel #10
0
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);
}
Beispiel #11
0
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);
}
Beispiel #12
0
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;
	}
}
Beispiel #13
0
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);
}
Beispiel #14
0
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;
}
Beispiel #15
0
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);
}
Beispiel #16
0
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;
}
Beispiel #17
0
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();
}
Beispiel #18
0
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;
}
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;
        }
    }
}
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();
	}
}
int main(void)
{
    float bedrag;
    float rentebedrag;
    
    do
    {
    printf("Voer hier je gespaarde bedrag in:\n");
    bedrag = GetFloat();
    }
    while (bedrag < 0);
    
    rentebedrag = bedrag * RENTE;
    printf("%.2f\n", rentebedrag);
    return 0;
}
Beispiel #22
0
// Gets a non-negative float from standard input
float read_input(const char *p_prompt)
{
    bool correct_input = false;
    float result;
    
    while (!correct_input)
    {
        printf("%s\n", p_prompt);
        result = GetFloat();
        
        if (result >= 0.0)
            correct_input = true;
    }
    
    return result;
}
Beispiel #23
0
SimpleString WBEvent::SParameter::CoerceString() const
{
	switch( m_Type )
	{
	case EWBEPT_None:		return "None";
	case EWBEPT_Bool:		return GetBool() ? "True" : "False";
	case EWBEPT_Int:		return SimpleString::PrintF( "%d", GetInt() );
	case EWBEPT_Float:		return SimpleString::PrintF( "%f", GetFloat() );
	case EWBEPT_Hash:		return SimpleString::PrintF( "%s", ReverseHash::ReversedHash( GetHash() ).CStr() );
	case EWBEPT_Vector:		return GetVector().GetString();
	case EWBEPT_Angles:		return GetAngles().GetString();
	case EWBEPT_Entity:		{ WBEntity* const pEntity = GetEntity().Get(); return pEntity ? pEntity->GetUniqueName() : "NULL"; }
	case EWBEPT_Pointer:	return SimpleString::PrintF( "Ptr: 0x%08X", GetPointer() );
	default:				return "Unknown";
	}
}
Beispiel #24
0
static  void    InNumber( void ) {
//==========================

    extended    value;
    intstar4    intval;
    int         col;

    col = IOCB->fileinfo->col; // save position in case of repeat specifier
    for(;;) {
        IOCB->fileinfo->col = col;
        if( IOCB->typ >= PT_REAL_4 ) {
            GetFloat( &value, ( IOCB->typ - PT_REAL_4 ) );
            switch( IOCB->typ ) {
            case PT_REAL_4:
                *(single PGM *)(IORslt.pgm_ptr) = value;
                break;
            case PT_REAL_8:
                *(double PGM *)(IORslt.pgm_ptr) = value;
                break;
            case PT_REAL_16:
                *(extended PGM *)(IORslt.pgm_ptr) = value;
                break;
            default:
                IOErr( IO_FREE_MISMATCH );
                break;
            }
        } else {
            GetInt( &intval );
            switch( IOCB->typ ) {
            case PT_INT_1:
                *(intstar1 PGM *)(IORslt.pgm_ptr) = intval;
                break;
            case PT_INT_2:
                *(intstar2 PGM *)(IORslt.pgm_ptr) = intval;
                break;
            case PT_INT_4:
                *(intstar4 PGM *)(IORslt.pgm_ptr) = intval;
                break;
            default:
                IOErr( IO_FREE_MISMATCH );
                break;
            }
        }
        FreeIOType();
        if( ( IOCB->rptnum-- <= 1 ) || ( IOCB->typ == PT_NOTYPE ) ) break;
    }
}
Beispiel #25
0
int main (void)
{
  
    printf ("How much change is due?\n");
    float change = 0;
    
    if (change <= 0)
      {
         do
         {   
         printf ("Please enter a positive numeric amount.\n");
         change = GetFloat();
         }
         while (change<=0);
         }
     int cents = (int)round(change * 100); 
     
     int coins = 0;
     
        while (cents >= 25) 
     {
        cents= cents-25;
        coins++;
     }
     
       while (cents >= 10)
     {
        cents = cents-10;
         coins++;
     }
     
        while (cents >= 5)
     {
        cents = cents -5;
        coins ++;
     }
     
        while (cents >= 1)
     {
        cents = cents-1;
        coins++;
     }
         
    
 printf("%d\n", coins);
     
 }
Beispiel #26
0
int main(void)
{
    int q=0, d=0, n=0, p = 0;
    float f; 
    
    do
    {
        printf("How much change do you owe(in dollars)?");
        f = GetFloat();
    }
    while (f<0);
    
    int cents = round(f * 100);
    
    while (cents >= 25)
    {
        q++;
        cents = cents - 25;
    }
    printf("quarters: %i\n" , q);
    
    while (cents >= 10)
    {
     
       d++;
        cents = cents - 10;
        
    }
    printf("dimes: %i\n" , d);
    
    while (cents >= 5)
    {
        n++;
        cents = cents - 5;
    }
    printf("nickels: %i\n" , n);
    
     while (cents >= 1)
    {
        p++;
        cents = cents - 1;
    }
     printf("pennies: %i\n" , p);
     
    int total = q+d+n+p;
    printf("total coins: %i\n" , total);
}
nsresult
nsSMILParserUtils::ParseSemicolonDelimitedProgressList(const nsAString& aSpec,
                                                       bool aNonDecreasing,
                                                       nsTArray<double>& aArray)
{
  nsresult rv = NS_OK;

  NS_ConvertUTF16toUTF8 spec(aSpec);
  const char* start = spec.BeginReading();
  const char* end = spec.EndReading();

  SkipBeginWsp(start, end);

  double previousValue = -1.0;

  while (start != end) {
    double value = GetFloat(start, end, &rv);
    if (NS_FAILED(rv))
      break;

    if (value > 1.0 || value < 0.0 ||
        (aNonDecreasing && value < previousValue)) {
      rv = NS_ERROR_FAILURE;
      break;
    }

    if (!aArray.AppendElement(value)) {
      rv = NS_ERROR_OUT_OF_MEMORY;
      break;
    }
    previousValue = value;

    SkipBeginWsp(start, end);
    if (start == end)
      break;

    if (*start++ != ';') {
      rv = NS_ERROR_FAILURE;
      break;
    }

    SkipBeginWsp(start, end);
  }

  return rv;
}
Beispiel #28
0
/**
 * Constructor for a Axis to load from Preferences
 * <p><b>Axis Preferences</b><br>
 * foo = channel. Either axis number, axis number, or pov direction (int)<br>
 * foo.js = joystick (int)<br>
 * </p>
 * @param axisConfig The configuration key for the axis
 */
Axis::Axis(std::string axisConfig) {
	auto pref = Preferences::GetInstance();
	config = axisConfig;

	if (!pref->ContainsKey(axisConfig.c_str())) {
		DriverStation::ReportError("[Axis] Attempting to load config '" + axisConfig + "' and could not find it");
		return;
	} else {
		axisChannel = pref->GetInt(axisConfig.c_str());
		auto stickNum = pref->GetInt((axisConfig + ".js").c_str(), 0); // Default to joystick 0
		stick = Joystick::GetStickForPort(stickNum);

		invert = pref->GetBoolean((axisConfig + ".invert").c_str(), false);
		deadband = pref->GetFloat((axisConfig + ".deadband").c_str());

	}
}
Beispiel #29
0
int main(void)
{
    float change;
    int coins = 0;
    
    //Prompts for how much change.  Repromts when a non-float or float is negative
    do
    {
        printf("How much change is owed? ");
        change = GetFloat();
    }
    
    while (change < 0);
    
    //multiplies by 100; easier to work with
    change = round(change * 100);
    coins = 0;
    
    while (change >= 25)
    {
        change -= 25;
        coins += 1;
    }      
    
    while (change >= 10)
    {
        change -= 10;
        coins += 1;
    }
    
    while (change >= 5)
    {
        change -= 5;
        coins += 1;
    }
    
    while (change > 0)
    {
        change -= 1;
        coins += 1;
    }
    
    printf("%i\n", coins);
    
    return 0;
}
Beispiel #30
0
nsresult
nsSMILParserUtils::ParseKeyTimes(const nsAString& aSpec,
                                 nsTArray<double>& aTimeArray)
{
  nsresult rv = NS_OK;

  NS_ConvertUTF16toUTF8 spec(aSpec);

  nsACString::const_iterator start, end;
  spec.BeginReading(start);
  spec.EndReading(end);

  SkipWsp(start, end);

  double previousValue = -1.0;

  while (start != end) {
    double value = GetFloat(start, end, &rv);
    if (NS_FAILED(rv))
      break;

    if (value > 1.0 || value < 0.0 || value < previousValue) {
      rv = NS_ERROR_FAILURE;
      break;
    }

    if (!aTimeArray.AppendElement(value)) {
      rv = NS_ERROR_OUT_OF_MEMORY;
      break;
    }
    previousValue = value;

    SkipWsp(start, end);
    if (start == end)
      break;

    if (*start++ != ';') {
      rv = NS_ERROR_FAILURE;
      break;
    }

    SkipWsp(start, end);
  }

  return rv;
}