|
-
April 27th, 2011, 05:41 PM
#1
My chessboard
here's my code and i need to get te outpu into a text file.
the output is a simple chessboard. i tried using fstream, printf but couldn't make it work
sorry for all the confusion in the earlier posts, i'm kinda desperate.
this code works fine, but only the ouput should be displayed like it is and also saved to a textfile
which must be named by the user.
the code:
#include<iostream>
using namespace std;
int main()
{
string character, b=" ",stop_go;//initialisation of variables
int size;
int n=1;
while (n>0) //while loop so the user can draw multiple times
{
cout<<"Give Chessboard Size:"<<endl; //read-in chessboard information and save in variables
cin>>size;
//so only odd numbers will be used
if(size%2==0)
{
cout<<"Only enter odd numbers; please try again"<<endl;
continue;
}
cout<<"Give a Character for your chessboard:"<<endl;
cin>>character;
//begin drawing chessboard
for(int k=1; k<=size //outer loop for vertical drawing
{
if (k%2==0)
for (int i=1; i<=size;i++) //inner loop voor horizontal drawing
{
if (i%2==0) cout <<character;
else cout<< b;
}
else
for (int i=1; i<=size;i++)
{
if (i%2==0) cout <<b;
else cout<< character;
}
cout<<endl;
k++;
}
//give user the choice to exit or draw again
cout<<"Press 'e' to exit or 'd' to try again \n please draw chessboard"<<endl;
cin>>stop_go;
if (stop_go=="e") n=0;
if (stop_go=="d") n=1;
}
system("pause");
return 0 ;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|