숫자를 입력하면 숫자가 계산되는 기능이 있습니다. 이것은 프로그램의 시작 부분에서 clock()과 관련이있는 함수를 호출하는 경우에만 수행됩니다. 내 변수의 나머지 부분에 clock()을 추가했지만 함수는 계산하지 않습니다. 특히 if 문에서.왜 함수가 중요하지 않습니까?
코드 :이 줄을 사용하여 함수를 호출하지 않는
#include <stdio.h>
#include <string>
#include <iostream>
#include <stdlib.h>
#include <windows.h>
#include "math.h"
#include <time.h>
#include <ctime>
#include <cstdlib>
#include <mmsystem.h>
void countbysec(int Seconds);
using namespace std;
int main(){
int secondsinput;
cout<<"Type how many seconds to cout \n";
cin>>secondsinput;
countbysec(secondsinput);
return 0;
}
void countbysec(int Seconds){
clock_t Timer;
Timer = clock() + Seconds * CLOCKS_PER_SEC ;
clock_t counttime = clock() + (Timer/Seconds);
clock_t secondcount = 0;
while(clock() <= Timer){
if(clock() == counttime){
counttime = counttime + CLOCKS_PER_SEC;
secondcount = secondcount + 1;
cout<<secondcount<<endl;
}
}
}
변수를 대문자로 표기하는 것은 약간 불규칙합니다. C++에서는 전통적으로 클래스 용으로 예약되었습니다. 이것은'Timer'가 클래스 인 것처럼 코드를 읽게하지만, 그렇지 않습니다. – tadman
"그것은 그것들을 카운트합니다." 이해할 수 없는. 당신이 의미하는 것을 분명하게 말하기에 충분한 작품을 사용하십시오. – philipxy
그것은 나를 위해 작동합니다. – Neil