Exemplo n.º 1
0
//Receive the N input test cases
void inputInt(int total){
	int X;
	if (ctr==total){
		printResult(result,ctr);
	}
	else{
		scanf("%d",&X);
		scanf("%c",&trash);
		if (X>0 && X<=100){
			scanf("%[^\n\t]s",input);
			char tmp[256]="";
			int checkY = toIntArray(arr,input,0,tmp,X);
			// calculate
			result[ctr]=0;
			calculate(result,arr,k);
			ctr++;
			k=0;
			if (checkY==0){
				printf("Please input Yn ( -100 <= Yn <= 100 )!\n");
				return;
			}
		}
		else{
			printf("Please input X ( 0 < X <= 100 )!");
			return;
		}
		inputInt(total);
	}
}
Exemplo n.º 2
0
static void testRandomBigReal() {
  DigitPool pool(-5);
  MersenneTwister64 rnd;
  for(;;) {
    int count  = inputInt(_T("Enter number of random numbers:"));
    int length = inputInt(_T("Enter length (decimal digits):"));
    const FullFormatBigReal low  = inputBigReal(pool, _T("Enter low :"));
    const FullFormatBigReal high = inputBigReal(pool, _T("Enter high:"));

    String fileName = format(_T("c:\\temp\\random%s-%s-length=%d.dat"), low.toString().cstr(), high.toString().cstr(), length);
    FILE *f = FOPEN(fileName, _T("w"));
    for(int i = 0; i < count; i++) {
      FullFormatBigReal x = randBigReal(low, high, length, &rnd, &pool);
      _ftprintf(f, _T("%s\n"), x.toString().cstr());
    }
    fclose(f);
  }
}
Exemplo n.º 3
0
void NumOfConn(int& numOfConn)
{
    cout <<"Number of connections: ";

    numOfConn = inputInt();

    if(numOfConn != 0)
        cout <<"\n--- Reading connections ---" << endl;
}
Exemplo n.º 4
0
void NumOfComp(int& numOfCom)
{
    cout <<"Number of computers: ";

    numOfCom = inputInt();

    if(numOfCom != 0)
        cout <<"\n--- Reading computers ---" << endl;
}
Exemplo n.º 5
0
void NumOfSci(int& numOfSt)
{
    cout <<"Number of computer scientists: ";

    numOfSt = inputInt();

    if(numOfSt != 0)
        cout <<"\n--- Reading scientist ---" << endl;
}
Exemplo n.º 6
0
//main program
int main(){
	int N;
	scanf("%d",&N);
	if(N>=1 && N<=100){
		inputInt(N);
	}
	else{
		printf("Please input N ( 1 <= N <= 100 )!");
	}

}
Exemplo n.º 7
0
int _tmain(int argc, TCHAR **argv) {
  for(;;) {
    const String   pattern    = inputString(_T("Enter pattern:"));
    const bool     ignoreCase = inputString(_T("Ignore case[yn]:")) == _T("y");
    const ShiftAnd A(pattern, ignoreCase);
    const int      maxErrors  = inputInt(_T("Enter maxErrors:"));
    for(;;) {
      const String text = inputString(_T("Enter text:"));
      if((text.length() > 0) && text[0] == _T('!')) break;
      const intptr_t i = A.searchApprox(text,maxErrors);
      _tprintf(_T("result:%zd\n"), i);
    }
  }
  return 0;
}
Exemplo n.º 8
0
//Checks if users input data is legal or not
void legalComputer(string& name, int& yearCre, string& tp, bool& wc)
{
   bool err = false;
   string ans;

   cout <<"Name: ";
   cin.sync();
   getline(cin, name);

   do{
       cout <<"Year of Creation: ";
       yearCre = inputInt();
       if(yearCre>0){
           err = false;
       }
       else{

           cout << "Please enter a valid date." << endl;
           err = true;
       }
   }while(err);


   cout <<"Type of Computer: ";
   cin.sync();
   getline(cin, tp);

   do{
       cout <<"Was the Computer ever built? y/n: ";
       cin >> ans;
       if(ans == "n" || ans == "N" || ans == "no" || ans == "NO" || ans == "No")
       {
           wc = false;
           err = false;
       }
       else if(ans == "y" || ans == "Y" || ans == "yes" || ans == "YES" || ans == "Yes")
       {
           wc = true;
           err = false;
       }
       else
       {
           cout << "Not a valid answer." << endl;
           err = true;
       }
   }while(err);
}
Exemplo n.º 9
0
void enterSong(void)
{
	if (state.flag == 0)
	{
		error(WORKING_ERROR);
	}
	else
	{
		songs song;
		system("cls");
		printf("Enter name of singer: ");
		gets_s(song.name, 100);
		printf("Enter title of song: ");
		gets_s(song.title, 100);
		printf("Enter length of song: ");
		song.length = inputInt();
		pushBack(song);
	}
}
Exemplo n.º 10
0
int main()
{
	int r = inputInt("please input the radius: ");
	diamond(r);
	return 0;
}
Exemplo n.º 11
0
void legalConnectionInput(int& IDpers, int& IDcomp, QSqlDatabase& db)
{
    bool error = false;
    IDpers = 0;
    IDcomp = 0;
    vector<Person> VECTpers;
    cout << "Inputing Person" << endl;
    QString person = getPeopleQueryString();
    QSqlQuery query = getQuery(db, person);
    int NUMpeople = printPersonTableINT(query, VECTpers);
    if(NUMpeople < 1)
        error = true;
    if(!error)
    {
        if(NUMpeople ==1)
        {
            cout << "1 person found and set" << endl;
            IDpers = NUMpeople -1;
            error = false;
        }
        else
        {
            cout << NUMpeople << " people found" << endl;
            cout << "Enter the row number of the correct person:";
            IDpers = inputInt();
            if(IDpers < 1)
            {
                cout << "Number not on list. Ending Input." << endl;
                error = true;
            }
            else
            {
                error = false;
                IDpers--;
                cout << "Person set." << endl;
            }
        } // else for if(NUMpeople ==1) END
        if(!error)
        {
            error = false; // Justin Case
            vector<Computer> VECTcomp;
            cout << "Inputing Computer" << endl;
            QString computer = getComputerQueryString();
            QSqlQuery query2 = getQuery(db, computer);
            int NUMcomputers = printComputerTableINT(query2, VECTcomp);
            if(NUMpeople < 1)
                error = true;
            if(!error)
            {
                if(NUMcomputers ==1)
                {
                    cout << "1 computer found and set" << endl;
                    IDcomp = NUMcomputers -1;
                    error = false;
                }
                else
                {
                    cout << NUMcomputers << " computers found" << endl;
                    cout << "Enter the row number of the correct computer:";
                    IDcomp = inputInt();
                    if(IDcomp < 1)
                    {
                        cout << "Number not on list. Ending Input." << endl;
                        error = true;
                    }
                    else
                    {
                        error = false;
                        IDcomp--;
                        cout << "Computer set." << endl;
                    }

                } // else for if(NUMcomputers ==1) END
                if(!error)
                    {
                        IDpers = search_for_id(db, VECTpers.at(IDpers));
                        IDcomp = search_for_id(db, VECTcomp.at(IDcomp));
                    } // if(!error) #3 END
            }
            else
                cout << "No computer found. Ending Input." << endl;
        } // if(!error) #2 END
    } // if(!error) #1 END
    else
        cout << "No person found. Ending Input." << endl;


}
Exemplo n.º 12
0
//Checks if users input data for person is legal or not
void legalPerson(string& name, string& sex, int& brth, int& dth)
 {
    bool err = false;
    string ans;
    brth = 0;

    cout << "Name: ";
    cin.sync();
    getline(cin, name);

    do{
        cout << "Gender - f/m: ";
        cin >> sex;
        if(sex[0] == 'f' || sex[0] == 'F'){
            sex = "Female";
            err = false;
        }
        else if(sex[0] == 'm' || sex[0] == 'M'){
            sex = "Male";
            err = false;
        }
        else{
            err = true;
            cout << "Input invalid, please enter 'f' for female or 'm' for male" << endl;
        }
    }while(err);

    do{
        cout <<"Year of Birth: ";
        brth = inputInt();
        if(brth > 0){
            err = false;
        }
        else{

            cout << "Please enter a valid date." << endl;
            err = true;
        }
    }while(err);

    do{
        cout <<"Is the person still alive? y/n: ";
        cin >> ans;
        if(ans[0] == 'n' || ans[0] == 'N')
        {
            do{
                cout <<"Year of Death: ";
                dth = inputInt();
                if(dth >= brth){
                    err = false;
                }
                else{
                    cout << "Please enter a valid date." << endl;
                    err = true;
                }
            }while(err);
        }
        else if(ans[0] == 'y' || ans[0] == 'Y') {
            dth  = '\0';
            err = false;
        }
        else {
            cout << "Please enter a valid letter." << endl;
            err = true;
        }
    }while(err);

 }
Exemplo n.º 13
0
int main()
{
    int r = inputInt("输入菱形半径");
    diamond(r);
    return 0;
}