0% found this document useful (0 votes)
35 views4 pages

STD Main (Num Cout Num (Num 0) Cout Num Cout Num System )

The document contains C++ code snippets that use conditional statements like if, else if, and else to test conditions and print corresponding output messages. The snippets include: 1) Checking if a number is positive or negative 2) Comparing two numbers and printing the smaller and larger 3) Validating if a number is a valid month 4) Printing the season based on the month number 5) Checking if a number is less than 50 6) Checking if a mark is between 0-50 7) Checking if a number is positive, negative, or zero 8) Grading based on total marks from two subjects
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views4 pages

STD Main (Num Cout Num (Num 0) Cout Num Cout Num System )

The document contains C++ code snippets that use conditional statements like if, else if, and else to test conditions and print corresponding output messages. The snippets include: 1) Checking if a number is positive or negative 2) Comparing two numbers and printing the smaller and larger 3) Validating if a number is a valid month 4) Printing the season based on the month number 5) Checking if a number is less than 50 6) Checking if a mark is between 0-50 7) Checking if a number is positive, negative, or zero 8) Grading based on total marks from two subjects
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

LAB 2 : PROGRAM CONTROL Activity 2A No1.

#include <iostream> using namespace std; void main() { int num; cout<<"entered a number to test if it is positive or not:"<<endl; cin>>num; if (num > 0) cout<<num<<" is positive\n"; else cout<<num<<"is negative\n"; system("pause"); }

No2. #include <iostream> using namespace std; void main() { int num1, num2; cout<<"insert two numbers :"<<endl; cin>>num1>>num2; if (num1 < num2){ cout<<"The smaller number is "<<num1<<"\n"; cout<<"The larger number is "<<num2<<"\n"; }else{ cout<<"The smaller number is "<<num2<<"\n"; cout<<"The larger number is "<<num1<<"\n"; }

No.3 #include <iostream> using namespace std; void main() { int month; cout<<"enter a month in numbering :"<<endl; cin>>month; if (month >=1 && month <=12) cout<<month<<" is a valid month.\n"; else cout<<month<<" is NOT a valid month.\n"; system("pause"); }

Activity 2B No.1

No2. #include <iostream> using namespace std; void main() { int month; cout<<"Please enter your month in number to determine the season:"<<endl; cin>>month; if((month==1) || (month==2) || (month==12)) cout<<"Winter\n"; else if((month==3) || (month==4) || (month==5)) cout<<"Spring\n"; else if((month==6) || (month==7) || (month==8)) cout<<"Summer\n"; else if((month==9) || (month==10) || (month==11)) cout<<"Fall\n"; else cout<<month<<" is not a valid month\n"; system("pause"); }

Activity 2C #include <iostream> using namespace std; int main() { int num; //variable cout<<"Enter your lucky number: "; cin >> num; if (num < 50) //if statement cout<<"Number is less than 50" << endl; return 0; } //header //function main

Activity 2D #include <iostream> using namespace std; int main() { int marks; //variable cout << "Enter your F2037 mark = "; cin >> marks; if ((marks > 0) && (marks < 50)) //if statement cout<<"FAILED!!!" << endl; return 0; //header //main function

Activity 2E #include <iostream> using namespace std; int main() { int num; cout << "Enter 1 number = "; cin >> num; if (num < 0) //if ..else statement cout << "You enter negative number" << endl; else if (num > 0) //if ..else statement cout << "You enter positive number" << endl; else //if ..else statement cout << " You enter zero number" << endl; return 0; }

LAB EXERCISE (SELECTION CONTROL) No.1

No.2 #include <iostream> using namespace std; void main() { int mark1, mark2, total; cout<<"Enter your first mark :"<<endl; cin>>mark1; cout<<"Enter your second mark :"<<endl; cin>>mark2; total=mark1+mark2; if (total<=50) cout<<"You Need To Work Hard"<<endl; else if ((total>=51) && (total<=79)) cout<<"You Are Good But You Can Do Better"<<endl; else if ((total>=80) && (total<=100)) cout<<"Excellent Work, Keep It Up" <<endl; system("pause"); }

You might also like