Developing Game 1 if else
Class Project: Fortune Teller in C++
Takes input from user , date of birth and time , and predicit any future.
Steps
1. We need a way that we can process all the date and time processed in one variable.
2. Than based on some processing we wan to get out 0,1,2
Part 1: lets make a way to generate one number from date and time (lucky lottery game)
| #include<iostream>
using namespace std; main() { int date=0; int time=0; int total=0; cout<<“fortune teller “<<endl; cout<<“Enter your date of birth DDMMYYYY”<<endl; cin>>date; cout<<“Enter todays time HHMM”<<endl; cin>>time; cout<<“your lucky number for lottery is “<<endl; total=date+time; cout<<total; } |
Part 2: compute a method so that the sum of data and time can be converted in to 0,1,2
We know that % is program that can convert a number in to our desired range for example %3 output always be 0,1,2, and will never be above 2. Same logic can be used here
| #include<iostream>
using namespace std; main() { int date=0; int time=0; int total=0; int rem=0; cout<<“fortune teller “<<endl; cout<<“Enter your date of birth DDMMYYYY”<<endl; cin>>date; cout<<“Enter todays time HHMM”<<endl; cin>>time; cout<<“your lucky number for lottery is “<<endl; total=date+time; cout<<total<<endl; rem=total%3; cout<<“your lucky friend is some one who has following digit in his/her roll number “<<rem; } |
Part 3: Showing a prediction statement , on the basis of 0 1 2 as per given values of user
| #include<iostream>
using namespace std; main() { int date=0; int time=0; int total=0; int rem=0; cout<<“fortune teller “<<endl; cout<<“Enter your date of birth DDMMYYYY”<<endl; cin>>date; cout<<“Enter todays time HHMM”<<endl; cin>>time; cout<<endl; cout<<“********************************************”<<endl; total=date+time; cout<<total<<endl; rem=total%3; cout<<endl;
cout<<” listen closely to what future perdicter has to say about you”<<endl; if(rem==0) { cout<<“bhai tu nay ITC main pass nahi hona “<<endl; } if(rem==1) { cout<<“you will be unable to submit next assignment “<<endl; } if(rem==2) { cout<<” you enemies will kill you soon “<<endl; } } |
Same program can be compiled using if else
| #include<iostream>
using namespace std; main() { int date=0; int time=0; int total=0; int rem=0; cout<<“fortune teller “<<endl; cout<<“Enter your date of birth DDMMYYYY”<<endl; cin>>date; cout<<“Enter todays time HHMM”<<endl; cin>>time; cout<<endl;
total=date+time; cout<<total<<endl; rem=total%3; cout<<endl; cout<<“********************************************”<<endl; cout<<endl; cout<<“********************************************”<<endl; cout<<” listen closely to what future perdicter has to say about you”<<endl; if(rem==0) { cout<<“bhai tu nay ITC main pass nahi hona “<<endl; } else { if(rem==2) { cout<<” you enemies will kill you soon “<<endl; } else { cout<< “you will pass the papers “; } } } |
Understanding how if else works
When remainder ==0
When remainder ==2
#gallery-1459-1 { margin: auto; } #gallery-1459-1 .gallery-item { float: left; margin-top: 10px; text-align: center; width: 33%; } #gallery-1459-1 img { border: 2px solid #cfcfcf; } #gallery-1459-1 .gallery-caption { margin-left: 0; } /* see gallery_shortcode() in wp-includes/media.php */- image0152
- image016
First published on fatsup.wordpress.com ↗







