Simpelt script, tidregning. Og et spørgsmål
Hej, jeg er rimlig ny i C++, jeg ønsker at den regner mere korrekt og også regner både minutter og sekunder ud. Hvordan gør jeg det?Og findes der er et sted med en beskrivelse af de forskellige datatyper, og hvilke værdier de bruges til og sådan?
Jeg har flgn. kode:
#include <iostream.h>
#include <math.h>
main ()
{
float usr_kbit; // Users connection to the net in KB/s
float chars_pr_secs; // How many chars that can be transferred pr. second
float file_size; // The size of the file the user wants to download
float hours; // How many hours it takes
float seconds; // How many seconds, is used temporarely to calculate the other values
cout << "How fast can you download the file? (In KB/s)\n";
cin >> usr_kbit; // Set the variable
chars_pr_secs = usr_kbit * 1024.0; // Calculate how many characters the user can download in seconds
cout << "How big is the file you want to download? (In MegaBytes)\n";
cin >> file_size; // Get how much the file is
file_size = file_size * 1024.0 * 1024.0; // Calculate how much bytes the download is
seconds = file_size / chars_pr_secs;
hours = floor(seconds / 3600.0);
cout << "\nTime to be used: " << hours << " hours\n";
return(0);
}