Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // Harjoitukset 7
- // Tehtävä 1-4
- // Ilmari Ahonen
- // 14I220B
- int nelio(int);
- float suorakaide(float, float);
- float matkanhinta(float, float, float);
- int palkka(int);
- int main() {
- int teht = 0;
- while (teht != 5){
- cout << "Valitse tehtava (1-4) tai lopetus (5) ";
- cin >> teht;
- if (cin.good() == false) {
- cout << "Virheellinen syote" << endl;
- break;
- }
- if (teht == 1) {
- int i;
- int tulos;
- cout << "Syota luku ";
- cin >> i;
- tulos = nelio(i);
- cout << "Luvun nelio on " << tulos << endl;
- continue;
- }
- else if (teht == 2) {
- float i1, i2;
- float tulos;
- cout << "Syota suorakaiteen leveys ";
- cin >> i1;
- cout << "Syota suorakaiteen korkeus ";
- cin >> i2;
- tulos = suorakaide(i1, i2);
- cout << "Suorakaiteen pinta-ala on " << tulos << endl;
- continue;
- }
- else if (teht == 3) {
- float i1, i2, i3;
- float tulos;
- cout << "Syota ajettava kilometrimaara ";
- cin >> i1;
- cout << "Syota auton kulutus (l/100km) ";
- cin >> i2;
- cout << "Syota bensan litrahinta ";
- cin >> i3;
- tulos = matkanhinta(i1, i2, i3);
- cout << "Matkan hinnaksi tulee " << tulos << " euroa." << endl;
- continue;
- }
- else if (teht == 4) {
- int i;
- int tulos;
- cout << "Syota tuntimaara ";
- cin >> i;
- tulos = palkka(i);
- cout << "Viikon bruttopalkka on " << tulos << " euroa" << endl;
- continue;
- }
- else if (teht == 5)
- break;
- else {
- cout << "Virheellinen tehtava" << endl;
- continue;
- }
- }
- system("pause");
- return 0;
- }
- int nelio(int n) {
- return n * n;
- }
- float suorakaide(float s1, float s2) {
- return s1 * s2;
- }
- float matkanhinta(float h1, float h2, float h3) {
- return (h1 * (h2 / 100.0f)) * h3;
- }
- int palkka(int p) {
- if (p <= 40) {
- return p * 10;
- }
- else {
- return 400 + ((p - 40) * 15);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement