Moving Fan:
In this post of shapes in c you will be able to construct the code for a moving fan in C++ using "*".
Code:
#include<iostream>#include<Windows.h>using namespace std;void fan1(const int size);void fan2(const int size);int main(){int size, time;cout<< "Enter the size of fan" << endl;cin>>size;cout<< "For how many seconds you want to switch on the fan" << endl;cin>>time;system("cls");for(int i=0 ; i<2*time ; i++){fan1(size);Sleep(500);system("cls");fan2(size);Sleep(500);system("cls");}return 0;}void fan1 (const int size){for(int i=0 ; i<=size ; i++){for(int j=0 ; j<=i ; j++){if(i!=size){if(j==0 || j==i)cout<< "* ";elsecout<<" ";}else if (i==size )cout<< "* ";}for(int spaces=i ; spaces<size ; spaces++)cout<<" ";for(int j=i ; j<=size ; j++){if(i==0)cout<< "* ";elseif(j==i || j==size)cout<<"* ";elsecout<<" ";}cout<<endl;}for(int m=0 ; m<=size ; m++){for(int spaces1=m ; spaces1<size ; spaces1++)cout<<" ";for(int n=0; n<=m ; n++){if(m==size)cout<<"* ";elseif(n==0 || n==m)cout<<"* ";elsecout<<" ";}for(int spaces1=0 ; spaces1<m ; spaces1++)cout<<" ";for(int n=m; n<=size; n++){if(m==0)cout<<"* ";elseif(n==m || n==size)cout<<"* ";elsecout<<" ";}cout<<endl;}}void fan2 (const int size){for(int i=0 ; i<=size ; i++){for(int j=0 ; j<i ; j++)cout<<" ";for(int spaces=i ; spaces<=size ; spaces++){if(i==0)cout<<"* ";elseif(spaces==i || spaces==size)cout<<"* ";elsecout<<" ";}for(int j=i ; j<size ; j++)cout<<" ";for(int j=0; j<=i ; j++){if(i==size)cout<<"* ";elseif(j==0 || j==i)cout<<"* ";elsecout<<" ";}cout<<endl;}for(int m=0 ; m<=size ; m++){for(int spaces1=m ; spaces1<=size ; spaces1++){if (m==0)cout<<"* ";elseif(spaces1==m || spaces1==size)cout<<"* ";elsecout<<" ";}for(int n=0; n<m ; n++)cout<<" ";for(int spaces1=0 ; spaces1<=m ; spaces1++){if(m==0 || m==size)cout<<"* ";elseif(spaces1==0 || spaces1==m)cout<<"* ";elsecout<<" ";}cout<<endl;}}
First of all it shows 22 errors
ReplyDeleteafter adding .h after iostream still it shows 10 errors
"Unable to open Windows.h
using 7th version of turbo C++
Please Correct it
We didn't checked it on Turbo C++. This is a code for Virtual studio versions. We'll check it and soon update you with it!!! :)
Deleteoh, wow It is working now
ReplyDeleteI have visual studio 2008 I have run this program on it and it is working now
Thank You so much
Please keep these programs coming
:)
I am glad that the code of moving fan worked on your side :)
DeleteOf course, we'll keep on coming with new shapes in c and c tutorial for beginners!!!
For latest version of visual studio, visit this page:
http://shapesinc.blogspot.com/2013/09/c-compiler-visual-studio-2012.html
Can you send me the alogrithm of this code plz
Delete