STD Main (Num Cout Num (Num 0) Cout Num Cout Num System )
STD Main (Num Cout Num (Num 0) Cout Num Cout Num System )
#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; }
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"); }