// Write a random number generator that returns a random folating point number between 0.0 and 1.0.
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int rand_float(int n);
int main()
{
int n, i;
double r;
srand(time(NULL));
cout << "Enter number of dice to roll: ";
cin >> n;
for (i - 1; i <= n; i++) {
r = rand_float();
cout << r << endl;
}
return 0;
}
// Random Float Function
//
double rand_float() {
return (double) rand()/RAND_MAX;
}
的「無符號整型」,可能的損失現在的問題/錯誤是警告警告C4244:「參數」:轉換從「time_t的」數據加上其他錯誤
警告1個警告C4244: 'argument':從'time_t'轉換爲'unsigned int',可能丟失數據
警告2警告C4552:' - ':操作符無效;預期操作者的副作用
錯誤3錯誤C2660:「rand_float」:函數不採取0參數
這個聲明是否指定零參數:'int rand_float(int n);'? –
我不這麼認爲? – zezhawk22
那麼爲什麼你提供了一個不同的定義,並且在你調用它時不傳遞任何參數? –