Hi, I'm trying to write a program to take in the names of 5 hard drives and their transfer speeds as well as the size of a folder in gigabytes to be transferred at the speed of that drive. It should then store the time taken in an array after calculating it. Then finally print out all of the drives names, speeds, the size of the folder, and the time taken for the folder to be transferred, all in columns using tabs. Then do the the same again but only list the fastest drive. Finally, the time taken should be rounded to 1 decimal place.
Before anyone asks, this is an exercise I am doing in school in truebasic, but I like to do them all in c++ so I can learn that too because c++ rocks.
Now, as you can see below, I have made a function to carry out the calculation and return an array with the transfer times in it. However, g++ keeps throwing up this error that my array is not defined so I wonder if I am returning it properly.
Here is the output from g++ just in case anyone is interested:Code:#include<iostream> #include<string> #include<cmath> using namespace std; float transferTime ( int hddSpeeds[], float sizeOfDir ); int main() { string hddNames[5]; int hddSpeeds[5]; float sizeOfDir; float counter = 0; int fastest; for ( int loop = 0; loop < 5; loop++ ) {//open loop cout<<"Please enter a harddrive name to be compared: "; cin>> hddNames[loop]; cout<<"Please enter the transfer speed of that drive in megabits per second: "; cin>> hddSpeeds[loop]; cout<<"Please enter the size of the directory being transferred in Gigabytes: "; cin>> sizeOfDir; }//end loop float transferTime( long hddSpeeds[], float sizeOfDir ); for ( int loop = 0; loop < 5; loop++ ) {//open loop if ( counter < transferRate[loop] ) {//open if fastest = loop; }//close if }//close loop float topspeed; topspeed = transferRate[fastest]; cout<<"Hard Drive\tTransfer rate Mbps\tDirectory Size\tTransfer time\n"; for (int loop = 0; loop < 5; loop++ ) {//open loop cout<< hddname[loop]"\t" << hddSpeeds[loop]"\t" << sizeOfDir"\t" << transferRate[loop]"\t\n"; }//close loop cout<<"\n"; cout<<"The fastest of the given Hard Drives was: "; cout<<"Hard Drive\tTransfer rate Mbps\tDirectory Size\tTransfer time\n"; cout<< hddname[fastest]"\t" << hddSpeeds[fastest]"\t" << sizeOfDir"\t" << std::fixed << std::setprecision(1) << topspeed <<; } float transferTime ( int hddSpeeds[], float sizeOfDir ) { float transferRate[5]; for (int loop = 0; loop < 5; loop++ ) {//open loop int dummy = hddSpeeds[loop]; transferRate[loop] = sizeOfDir * 1024 * 8/dummy; }//close loop return transferRate[]; }
The last line of the error output is the one which really has me confused. Should I be doing something at the start of the function?Code:hdd.cpp: In function ‘int main()’: hdd.cpp:28: error: ‘transferRate’ was not declared in this scope hdd.cpp:34: error: ‘transferRate’ was not declared in this scope hdd.cpp:38: error: ‘hddname’ was not declared in this scope hdd.cpp:38: error: expected `;' before string constant hdd.cpp:43: error: ‘hddname’ was not declared in this scope hdd.cpp:43: error: expected `;' before string constant hdd.cpp: In function ‘float transferTime(int*, float)’: hdd.cpp:54: error: expected primary-expression before ‘]’ token
Thanks in advance,
Calef13



LinkBack URL
About LinkBacks


