fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int creditHour; // intialize number of credit hours
  6. int studyHours; // intialize number of study hours
  7. int actualStudyHours; // intialize the actual number of hours the student spends studying
  8. int diffStudyHours; // intialize the difference between actual study hours and the the amount of hours they should be studying
  9.  
  10. cin >> creditHour; // take input of number of credit hours from user
  11. studyHours = creditHour * 3; // assign study hours with credit hours multiplied by 3
  12. cout << studyHours << endl; //output number of hours you should spend studying
  13.  
  14. cout << "How many hours do you actually spend studying?" << endl; // Output this question
  15. cin >> actualStudyHours; // take input of how many hours the user actually spends studying
  16.  
  17. diffStudyHours = studyHours - (studyHours - actualStudyHours); // find the difference between actual study hours and the the amount of hours they should be studying
  18. cout << diffStudyHours << endl; // Output the difference
  19. return 0;
  20. }
Success #stdin #stdout 0s 4224KB
stdin
15
5
stdout
45
How many hours do you actually spend studying?
5