void Town::refreshPrices() { for(Item i : itemReference) { updatePrice(i); transactionLog[i]=TransactionTuple(0,0); } }
void updateProductPriceMenu() { int id, newPrice; printf("Id of the product: "); scanf("%d", &id); printf("New price: "); scanf("%d", &newPrice); int result = updatePrice(id, newPrice); if (result == 0) { printf("Price was updated!"); } else { printf("Unknown id!"); } }
int main() { FILE *fp; int choice; int i=0; if ((fp = fopen("books.dat","rb+"))==NULL) //create binary file with blank records if file pointer returns NULL { printf("File does not exist\nCreating Binary File with blank records..."); struct book blankBook = { "","",0,0,0.0,0.0}; fp = fopen("books.dat","wb+"); for ( i = 1; i <= 100; i++ ) //write 100 blank book structures { fwrite( &blankBook, sizeof( struct book ), 1, fp ); } fclose ( fp ); main(); } else //menu { while ( ( choice = enterChoice() ) != 5 ) { switch ( choice ) { case 1: writeToTextFile( fp ); break; case 2: updatePrice( fp ); break; case 3: newBook( fp ); break; case 4: deleteBook( fp ); break; default: printf( "Incorrect choice\n" ); break; } } fclose( fp ); } return 0; }
void updateStock() { int i; do { printf("----------------------------------------------------\n"); printf("Push 1 to add to stock.\n"); printf("Push 2 to delete from stock.\n"); printf("Push 3 to update price of stock.\n"); printf("Push 4 to update quantity.\n"); printf("Push 5 or higher to go back to main.\n"); printf("?: "); scanf("%d", &i); switch(i) { case 1: printf("\n----------------------------------------------------\n"); addStock(sFile1); printf("----------------------------------------------------\n\n"); break; case 2: printf("\n----------------------------------------------------\n"); delStock(sFile1); printf("----------------------------------------------------\n\n"); break; case 3: printf("\n----------------------------------------------------\n"); updatePrice(sFile1); printf("----------------------------------------------------\n\n"); break; case 4: printf("\n----------------------------------------------------\n"); updateQuantity(); printf("----------------------------------------------------\n\n"); break; } } while(i<5); }
void LLInspectObject::update() { // Performance optimization, because we listen to updates from select mgr // but we're never destroyed. if (!getVisible()) return; LLObjectSelection* selection = LLSelectMgr::getInstance()->getSelection(); if (!selection) return; LLSelectNode* nodep = selection->getFirstRootNode(); if (!nodep) return; updateButtons(nodep); updateName(nodep); updateDescription(nodep); updateCreator(nodep); updatePrice(nodep); LLViewerObject* obj = nodep->getObject(); if(!obj) return; if ( mObjectFace < 0 || mObjectFace >= obj->getNumTEs() ) { return; } // Does this face have media? const LLTextureEntry* tep = obj->getTE(mObjectFace); if (!tep) return; mMediaEntry = tep->hasMedia() ? tep->getMediaData() : NULL; if(!mMediaEntry) return; mMediaImpl = LLViewerMedia::getMediaImplFromTextureID(mMediaEntry->getMediaID()); updateMediaCurrentURL(); updateSecureBrowsing(); }
void ContributoriesWidget::updateUi() { ui->btnAddProject->setEnabled( _modelProjects->getSelectedProjects().count() < ((Delegates::ProjectComboDelegate*) ui->tblProjects->itemDelegateForColumn(0))->getProjects().count() && _modelProjects->allProjectsChosen()); ui->btnRemoveProject->setEnabled( ui->tblProjects->currentIndex().row() != -1); if(_modelProjects->getSelectedProjects().count() > 0) { ui->btnAddPrestation->setEnabled(true); ui->btnRmovePrestation->setEnabled(true); ui->lbContributoriesProject->show(); } else { ui->btnAddPrestation->setEnabled(false); ui->btnRmovePrestation->setEnabled(false); ui->lbContributoriesProject->show(); } updatePrice(); }
int main(void){ /************************** Initializing variables ***************************/ int i, j; //Misc counter int workforcePercentage; // Total amount of the population that is // workforce. int growthPercentage; // Total amount of population growth float taxCollection; // Money Collected from Taxes. float productionCost; // Cost to produce resources int consumed; // Amount of the Good Consumed. float goodReserve; // Amount of a Good to Reserve float fluxFactor; // Fluctuation Factor float fluxPrice; // Good price based on the fluctuation systemDemographics SystemData; // System Demographics production Products; // Produced Product data /******************************* Main Program ********************************/ // Seeding Randomizer srand(time(NULL)); // Loading Settings printf("Loading Config.ini...."); if(loadConfig()){ exit(0); } printf("Done.\n"); // Connecting to DB printf("Connecting to DB..."); if(connectToDB()){ exit(0); } printf("Done.\n"); // Loading Goods printf("Loading Goods..."); loadGoods(); printf("Done.\n"); // Setting Good Rates productionRate = malloc(numberOfGoods * sizeof(goodRate)); consumptionRate = malloc(numberOfGoods * sizeof(goodRate)); productionFactor = malloc(numberOfGoods * sizeof(goodRate)); // Loading Rates printf("Loading Consumption and Production Rates..."); if(loadRates()){ exit(0); } printf("Done.\n"); // Loading Markets printf("Loading Markets..."); loadDestinations(); if(loadMarkets()){ exit(0); } printf("Done.\n"); // Cycling through each market for(i = 0; i < numberOfDestinations; i++){ // Loading Demographic Data SystemData = loadSystemDemographics(destinations[i].destinationID); // Setting Growth growthPercentage = ((rand() % 10) + 1) * ((rand() % 2) ? 1:-1); SystemData.pop += round(SystemData.pop * ((float)growthPercentage/100)); // Setting Workforce workforcePercentage = ((rand() % 25) + 1); SystemData.workPop = round(SystemData.pop * ((float)workforcePercentage / 100)); // Collecting Taxes taxCollection = (SystemData.workPop * SystemData.taxes); SystemData.funds += (SystemData.workPop * taxCollection); updateDemographics(SystemData); //Producing/Consuming Goods productionCost = 0; for(j = 0; j < numberOfGoods; j++){ Products = produceGood(SystemData.systemID, goodsID[j], SystemData.workPop); // Removing workers used to produce this good from work popultion (SystemData.workPop -= Products.workers); if(SystemData.workPop < 0){ SystemData.workPop = 0; } // Updating Total Production Cost for the System productionCost += Products.cost; // Calculating Consumption Amount of the Good consumed = ((SystemData.pop * consumptionRateForGood(goodsID[j])) * (0 -1)); // Updating System's Stock updateStock(SystemData.systemID, goodsID[j], consumed); // Determining Amount to reserve goodReserve = ((float)consumed * (0 - 1)) * TICKS_TO_RESERVE_FOR; // Calculating Factor fluxFactor = 1 - ((stockLevel(SystemData.systemID, goodsID[j]) - goodReserve)/goodReserve); // Calculating New Sell Price fluxPrice = fluxFactor * goodPrice(goodsID[j], SystemData.systemID); // Did it cost more to produce then the current Sell Price if(goodPrice(goodsID[j], SystemData.systemID) - calculateProductionCost(SystemData.systemID, goodsID[j]) < 0){ // Add the difference to the new Sell Price. fluxPrice += (calculateProductionCost(SystemData.systemID, goodsID[j]) - goodPrice(goodsID[j], SystemData.systemID)); } // Update New Sell Price updatePrice(SystemData.systemID, goodsID[j], fluxPrice); } // Good Cycle for() // Update Taxes if(taxCollection - productionCost < 0){ updateTaxes(SystemData.systemID, 1); } else { updateTaxes(SystemData.systemID, -1); } }// Markets Cycle for() // Clearing memory printf("Clearing Memory..."); mysql_free_result(result); iniparser_freedict(settings); free(destinations); free(markets); printf("Done.\n"); return 0; }