Created
September 3, 2015 22:18
-
-
Save halldorel/5a6de182e24c18c50909 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example program | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main() | |
{ | |
double scores = 0; | |
double totals = 0; | |
int i = 0; | |
int N = 0; | |
cout << "How many exercises to input: "; | |
cin >> N; | |
// Eitt stk. línubil prentað út | |
cout << endl; | |
if (N < 0) { | |
cout << "Input at least one exercise!"; | |
exit(0); | |
} | |
while (i < N) { | |
double score = 0; | |
double total = 0; | |
// Lesum inn score | |
cout << "Score received for exercise " << i << ": "; | |
cin >> score; | |
// Lesum inn total fyrir score | |
cout << "Total points possible for exercise " << i << ": "; | |
cin >> total; | |
// Söfnum nýju score og total gildunum í safnbreyturnar scores og totals | |
// scores += score; | |
// er það sama og | |
// scores = scores + score; | |
// að sama skapi væri t.d. | |
// a += 1; | |
// svipað og | |
// a++; (eða reyndar ++a;) | |
scores += score; | |
totals += total; | |
// Hækkum i um einn | |
i++; | |
// Eitt stk. línubil prentað út | |
cout << endl; | |
} | |
// Hér er while loopunni lokið, og reiknum við út og prentum: | |
double percentage = scores/totals * 100; | |
printf("Your total is %.2f out of %.2f, or %.2f%%.", scores, totals, percentage); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment