Skip to content
Snippets Groups Projects
Commit cd71a50c authored by Andreas Blakli's avatar Andreas Blakli
Browse files

La til:

skirvKlokkeslett() funk.
lesTall() funk.
i hjelpefunksjoner.cpp og hjelpefunksjoner.h.
parent c350d037
Branches
No related tags found
No related merge requests found
......@@ -87,3 +87,34 @@ vector<string> HjelpeFunksjoner::splittStreng(const char& splittPa, const string
split.push_back(tmp);
return split;
}
void HjelpeFunksjoner::skrivKlokkeslett(const int& time, const int& min) {
if (time <= 9)
cout << "0" << time;
else
cout << time;
cout << ":";
if (min <= 9)
cout << "0" << min;
else
cout << min;
}
// Basert på Frodes lesInt() funk fra lesData3.cpp
int HjelpeFunksjoner::lesTall() {
char buffer[MAX_CHAR] = "";
int tall = 0;
bool feil = false;
do {
feil = false;
cin.getline(buffer, MAX_CHAR);
tall = atoi(buffer);
if (tall == 0 && buffer[0] != '0') {
feil = true;
std::cout << "\nError: Ikke et tall!" << '\n';
}
} while (feil);
return tall;
}
\ No newline at end of file
......@@ -7,6 +7,8 @@
#include <regex>
#include <string>
#include "konstanter.h"
class HjelpeFunksjoner {
public:
std::string rensStreng(std::string str);
......@@ -14,6 +16,8 @@ class HjelpeFunksjoner {
bool erBokstav(std::string str);
std::string gjorOmTilStorBokstav(const std::string & str);
std::vector<std::string> splittStreng(const char & splittPa, const std::string & str);
void skrivKlokkeslett(const int& time, const int& min);
int lesTall();
};
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment