List of all available Websheets
Viewing cpp/conditionals/nestedec by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | Repeat the extra credit exercise which lets a user type in their score on a project (0-100) then ask if they completed the extra credit. The user will type <tt>y</tt> or <tt>n</tt> to answer the question and then receive 10 bonus points if they did complete the extra credit. However, the max score that they can receive should be 100 (so a score of 91 would max out at 100, receiving only 9 extra credit points). Use a nested <tt>if</tt> statement to achieve this behavior. |
Public permissions | |
Remarks Comments, history, license, etc. | Copied from problem cpp/conditionals/extracredit (author: redekopp@usc.edu) Copied from problem cpp/control/flag (author: daveagp@gmail.com) |
Engine | |
Template / Reference solution |
using namespace std; int main() { int score; char ans; cout << "What was your score?" << endl; cin >> score; cout << "Did you complete the extra credit?" << endl; cin >> \[ans ]\; \[ if(ans == 'y') { if(score + 10 > 100) { score = 100; } else { score += 10; } } ]\ cout << "Final score: " << score << endl; return 0; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {"stdin": "95 y", "args": ""}, {"stdin": "73 n", "args": ""}, {"stdin": "91 y", "args": ""}, {"stdin": "89 y", "args": ""} ] |
Solution visibility |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.