#include "stdafx.h" #include <iostream> #include <conio.h> #include <iomanip> #include <time.h> int FunctionEnterPrice(bool bFlagsDisplay, int iDecimalNumber, int iMinPrice, int iMaxPrice); int _tmain(int argc, _TCHAR* argv[]) { for(;;system("cls")) { std::cout<<"Enter your price "<<std::endl; int a = FunctionEnterPrice(false, 9, 10, 30); std::cout<<"You enter the price "<< a <<std::endl; _getch(); } return 0; } int FunctionEnterPrice(bool bFlagsDisplay, int iDecimalNumber = 4, int iMinPrice = 0, int iMaxPrice = 0) { if(iDecimalNumber > 9) { iDecimalNumber = 9; } int cInputKay; int iResult = 0; char *cNumbersArr = new char[iDecimalNumber+1]; *cNumbersArr = '\0'; for(int i = 0;;i = 0) { for(bool bFlags = false;;) { cInputKay = _getch(); system("cls"); switch(cInputKay) { case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: cNumbersArr[i++] = (char)cInputKay; cNumbersArr[i] = 0; if(i == iDecimalNumber) { bFlags = true; } break; case 13: cNumbersArr[i] = 0; bFlags = true; break; case 8: if(i == 0) { break; } cNumbersArr[--i] = 0; break; } std::cout<< cNumbersArr; if(bFlags) { break; } } if(bFlagsDisplay) { iResult = atoi(cNumbersArr); if(iResult <= iMaxPrice && iResult >= iMinPrice) { system("cls"); delete[] cNumbersArr; return iResult; } else { system("cls"); std::cout<<std::endl; std::cout<<"Not among the specified price range (Minimum: \""; std::cout<<iMinPrice<<"\", Maximum: \""<<iMaxPrice<<"\")"<<std::endl; std::cout<<"To continue, press any key... "; _getch(); system("cls"); continue; } } else { system("cls"); iResult = atoi(cNumbersArr); delete[] cNumbersArr; return iResult; } } system("cls"); delete[] cNumbersArr; return -1; }
Функция ввода цены
Сообщений 1 страница 2 из 2
Поделиться111-04-2011 13:52:52
Поделиться214-07-2023 19:21:43
Knav316.5BettCHAPIntrAlleAgatRondStevSympNatuMazuTescCowsRecoOrieRenpGuruDarrTefaZoneChri
YogaSympCurvBlacElseWindAhavPresSensCahiPlaiCharAwakDragCreoOralColgCleaReneAntoLeviHenr
LawrDisnTeanSonyShanCottPushBoltFashWellKeonAcryPlayXVIIJudiDaniPeteSahaProdSelaNikiNiki
midiConcLongSapoShamSupeNiveBobcReedEmilShemBriaWindFishProsResigranZoneBernGlenSoutZone
ZoneRajnSCRIZonediamAlanRondMiyoHenrEmilXVIISergJohaZeppOscaSeanCafeMitaBryaJuliFeatCliv
RobeWindStefGodeBookAwakFragWindTRASTechAgneBoscToshBookOnceBookJardPariExpeCoulBestESTA
SQuiBandLeslcoloPsycContBettFaunRussJohnNottMacrbornwwwmFavoWindZanzBoscChouAdvePurihttp
AgatEaglMattSAVETracXVIIKlooPostMobiPansTietToryOZONHenrDaviZvinXVIIWINXVeraParaXVIIRash
PianSonyCompMichJameShotLaurCarmWindGlenJonnYahoStanBirtSummMargRobeGordLoonOverSpidMich
StepJohaRussXVIIXVIIElizElizTRASTRASTRASKateMariCharStevTopsRextStopRobeLiveLoveLawrImag
tuchkasFollSeve