-
Notifications
You must be signed in to change notification settings - Fork 0
/
cake.txt
37 lines (28 loc) · 1.08 KB
/
cake.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
using namespace std;
int main()
{
int slices = 0; //number of slices
int present_students; //number of present students
int excess = 0; //number of excess slices
string result = ""; //final result to be evaluated later
//input value for cake slices
cout << "Enter number of cake slices: ";
cin >> slices;
//input value for present students
cout << "Enter number of present student(s): ";
cin >> present_students;
/*
Evaluate the result. If the excess if 0 then it is
exactly distributed. Otherwise, there is an excess greater than 0
*/
excess = slices - present_students;
//excluding the bracket since only a single line of code will be executed
if(excess == 0)
result = "Exact for all\n"; //final result if the excess is 0
else
result = "Excess " + to_string(excess) + " slices\n"; //final result if the excess is > 0
//display the final result. Also adding a pre-line break for readability
cout << "\n" << result;
return 0;
}