Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.

Similar presentations


Presentation on theme: "Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops."ā€” Presentation transcript:

1

2

3 Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops

4 Read in a year and determine if it is a leap year. A leap year is a year that is evenly divisible by 4 and not by 100. Or, a year that is evenly divisible by 400 is also a leap year.

5 Prompt Read in year Leap Year? Is not leap year Is leap year End Start TF

6 //Helen Kow CS 265 Program #1 //This program tells you if a year is a leap year or not #include "stdafx.h" #include using std::cin; using std::cout; using std::endl; int main() { int year, rem4, rem100, rem400; cout <<"Enter a year "; cin>> year; rem4 = year%4; rem100 = year %100; rem400 = year % 400; if ( rem4 == 0 && rem100 != 0 || rem400 == 0) cout << endl << year << " is a leap year " << endl; else cout << endl << year << " is not a leap year \nā€œ; return 0; }

7 //Helen Kow CS 265 Program #1 //This program tells you if a year is a leap year or not

8 #include "stdafx.h" #include using std::cin; using std::cout; using std::endl;

9 int main() { //code goes here return 0; }

10 int year, rem4, rem100, rem400; year rem4 rem400 rem100

11 cout <<"Enter a year "; cin>> year; 2018 year rem4 rem400 rem100

12 rem4 = year%4; rem100 = year %100; rem400 = year % 400; 2018 2 18 year rem4 rem400 rem100

13 if ( rem4 == 0 && rem100 != 0 || rem400 == 0) cout << endl << year << " is a leap year " << endl; else cout << endl << year << " is not a leap year \nā€œ; 2018 2 18 year rem4 rem400 rem100

14

15 Read in a year and determine if it is a leap year. A leap year is a year that is evenly divisible by 4 and not by 100. Or, a year that is evenly divisible by 400 is also a leap year. Allow the user to repeat the program as many times as they desire.

16 While condition is true Code to be repeated _ _ _ _ _ _ _ _ _ _ _ _ | | | | | | | | |_ _ _ _ _ _ _ _ _

17 do { //code to be repeated } while (some condition is true );

18 Prompt Read in year Leap Year ? Is not leap year Is leap year Start End Play again? while again == true _ _ _ _ _ _ _ _ _ _ _ _ _ |||||||||||||||||||||||||||||||||| _ _ _ _ _ _ Flowchart with loop

19 //Helen Kow CS 265 Program #1 //This program tells you if a year is a leap year or not #include "stdafx.h" #include using std::cin; using std::cout; using std::endl; int main() { int year, rem4, rem100, rem400; char again; do { cout <<"Enter a year "; cin>> year; rem4 = year%4; rem100 = year %100; rem400 = year % 400; if ( rem4 == 0 && rem100 != 0 || rem400 == 0) cout << endl << year << " is a leap year " << endl; else cout << endl << year << " is not a leap year " << endl; cout << "\nPlay again ?? "; cin >> again; } while (again == 'y'); return 0; } 1 2 3

20

21 Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops


Download ppt "Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops."

Similar presentations


Ads by Google