473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

help me in this prg

#include"stdio.h"
#include<conio.h>
#include<math.h>
void main()
{
int row,result;
char col;
clrscr();
printf("enter the row\n");
scanf("%d",&row);
printf("enter the col\n");
scanf("%d",&col);
result=row+col;
if(result<96||result>110)
printf("not valid");
else
{
if(result%2==0)
printf("black");
else
printf("white");
}
getche();
}
this is my prg for color of the squares in chess board i dont know wats
the mistake in this its not getting executed correctly i want this prg
to get the square name eg:a1 from the user and display the output that
it is whether black or white i had initialised col as char and made it
as ascii value using %d in scanf and thus using it in result i even
want a if statement to print the invalid statement if the inout given
is not valid eg:char >h and num>8

Sep 26 '06 #1
8 1916

anand devarajan wrote:
#include"stdio.h"
#include<conio.h>
#include<math.h>
void main()
{
int row,result;
char col;
clrscr();
printf("enter the row\n");
scanf("%d",&row);
printf("enter the col\n");
scanf("%d",&col);
result=row+col;
if(result<96||result>110)
printf("not valid");
else
{
if(result%2==0)
printf("black");
else
printf("white");
}
getche();
}
this is my prg for color of the squares in chess board i dont know wats
the mistake in this its not getting executed correctly i want this prg
to get the square name eg:a1 from the user and display the output that
it is whether black or white i had initialised col as char and made it
as ascii value using %d in scanf and thus using it in result i even
want a if statement to print the invalid statement if the inout given
is not valid eg:char >h and num>8
i need full executable prg for this

Sep 26 '06 #2
anand devarajan <is**********@gmail.comwrote:
#include"stdio.h"
#include<conio.h>
#include<math.h>
void main()
Three big no-no's already, and that's before you even get to the code.
Try a properly indented C program (which was not what you posted):

#include <stdio.h>
#include <math.h>

int main(void)
{
int row,result,col;
printf("enter the row\n");
scanf("%d",&row);
printf("enter the col\n");
scanf("%d",&col);
result=row+col;
if(result<96||result>110)
printf("not valid");
else {
if(result%2==0)
printf("black\n");
else
printf("white\n");
}
return 0;
}

This obviously isn't correct, but a regular might now be willing to
attempt to help you. Examine the differences between your code and
this closely.

I've snipped the rest of your post, because it was unparseable.
Please write in English, like this. Usenet is not a text message
service.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Sep 26 '06 #3
"anand devarajan" writes:

I don't know what your intent is, but I will offer an idea anyway. Feel
free to ignore what I say.
#include"stdio.h"
#include<conio.h>
#include<math.h>
void main()
{
int row,result;
char col;
clrscr();
printf("enter the row\n");
scanf("%d",&row);
printf("enter the col\n");
scanf("%d",&col);
result=row+col;
Adding rows and columns makes me nervous. Isn't the idea to uniquely
identify a cell? Is 5+3 different than 3+5? I would expect to see a
muilitply in there too.
if(result<96||result>110)
printf("not valid");
else
{
if(result%2==0)
printf("black");
else
printf("white");
}
getche();
}
this is my prg for color of the squares in chess board i dont know wats
the mistake in this its not getting executed correctly i want this prg
to get the square name eg:a1 from the user and display the output that
it is whether black or white i had initialised col as char and made it
as ascii value using %d in scanf and thus using it in result i even
want a if statement to print the invalid statement if the inout given
is not valid eg:char >h and num>8
Toget any serious help you will have to get rid of conio.h and its spawn.
It is not standard and no real need for it leaps out at me.
Sep 26 '06 #4
anand devarajan wrote:
#include"stdio.h"
Should be <stdio.h>
#include<conio.h>
Not part of the C standard, so should not be used in this newsgroup.
#include<math.h>
Not used.
void main()
int main(void)
{
int row,result;
char col;
clrscr();
Not a standard function.
printf("enter the row\n");
From the description of the program below, you should be asking
for the column first.
scanf("%d",&row);
If you are going to use two scanf()s, then you must gobble up the
rest of the first line, including the terminating newline,
before trying the second scanf(). You might want to consider
combining the two, so that the user can enter 'a1' instead of 'a'
and then '1' without getting a superfluous prompt.

You should also check the input for validity before proceeding.
printf("enter the col\n");
scanf("%d",&col);
The correct format for a character is %c. This input also needs
to be checked for validity.
result=row+col;
if(result<96||result>110)
You should never use magic numbers like these. This check is
also wrong. Invalid input passes the test (col: k; row: -5), and
valid input fails (col: h; row: 8). Additionally, not all
character sets have all the letters in contiguous blocks.
printf("not valid");
This and the following printf()s need terminating newlines.
else
{
if(result%2==0)
printf("black");
else
printf("white");
}
getche();
Not a standard function. You also need a return:

return 0;
}
this is my prg for color of the squares in chess board i dont know wats
the mistake in this its not getting executed correctly i want this prg
to get the square name eg:a1 from the user and display the output that
it is whether black or white i had initialised col as char and made it
as ascii value using %d in scanf and thus using it in result i even
want a if statement to print the invalid statement if the inout given
is not valid eg:char >h and num>8

--
Thomas M. Sommers -- tm*@nj.net -- AB2SB

Sep 26 '06 #5

"anand devarajan" <is**********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>
anand devarajan wrote:
>#include"stdio.h"
#include<conio.h>
This is not standard C.
>#include<math.h>
void main()
{
int row,result;
char col;
clrscr();
Not standard C
> printf("enter the row\n");
scanf("%d",&row);
printf("enter the col\n");
scanf("%d",&col);
Wrong. col is a char. You cannot read it as an integer.
> result=row+col;
Why are you adding a char to an int?
> if(result<96||result>110)
printf("not valid");
else
{
if(result%2==0)
printf("black");
else
printf("white");
}
getche();
Not standard C

>}
this is my prg for color of the squares in chess board i dont know wats
the mistake in this its not getting executed correctly i want this prg
to get the square name eg:a1 from the user and display the output that
it is whether black or white i had initialised col as char and made it
as ascii value using %d in scanf and thus using it in result i even
want a if statement to print the invalid statement if the inout given
is not valid eg:char >h and num>8
i need full executable prg for this
A simpler algorithm:
Given a column in row 1, you can determine if it should
be black or white.
If the row is even, invert your answer.

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
Sep 26 '06 #6
anand devarajan wrote:
#include"stdio.h"
^^^^^^^^^
This suggests you are using your own private version of "stdio.h"
rather than the system header <stdio.h>. If that is the case, then
nothing in your "stdio.h" is known to us, and we cannot comment on your
use of it.
#include<conio.h>
^^^^^^^^^
There is no such standard header as <conio.h>. Nothing in your
implementation's <conio.his known to us, and we cannot comment on your
use of it.
#include<math.h>
^^
By the way, a single space would not cost you much. The cost (using
some white space) is tiny compared to the the reward (improving
readability). Similar comments hold for your indentation below.
void main()
^^^^
main, by definition, returns an int in a hosted implementation. All
bets are off once you make this tyro's error.
{
int row,result;
char col;
clrscr();
^^^^^^
There is no such standard function.
printf("enter the row\n");
scanf("%d",&row);
printf("enter the col\n");
scanf("%d",&col);
^^^
You are telling scanf that it should store a (decimal) int into what
is actually a char. Unless ints and chars are the same thing for your
implementation -- fairly rare -- then you are in trouble. But you don't
want a value interpreted as an integer, you are expecting a value from
"abcdefgh" (and your program should say say). The specifier you want
here for a char is "%c".
result=row+col;
^^^^^^^
This is obviously wrong. It assumes that 'a'...'h' have certain
encodings not assured by any means. You could easily look up the
address of col in an array holding "abcedefgh", returned as pointer from
strchr, and subrract the base address of the array when the returned
value is not NULL, giving a value [0..8] to use. This would be portable
and not raise many eyebrows.
if(result<96||result>110)
printf("not valid");
else
{
if(result%2==0)
printf("black");
else
printf("white");
}
getche();
}
this is my prg for color of the squares in chess board i dont know wats
the mistake in this its not getting executed correctly i want this prg
to get the square name eg:a1 from the user and display the output that
it is whether black or white i had initialised col as char and made it
as ascii value using %d in scanf and thus using it in result i even
want a if statement to print the invalid statement if the inout given
is not valid eg:char >h and num>8
Sep 26 '06 #7
"osmium" <r1********@comcast.netwrites:
"anand devarajan" writes:

I don't know what your intent is, but I will offer an idea anyway. Feel
free to ignore what I say.
>#include"stdio.h"
#include<conio.h>
#include<math.h>
void main()
{
int row,result;
char col;
clrscr();
printf("enter the row\n");
scanf("%d",&row);
printf("enter the col\n");
scanf("%d",&col);
result=row+col;

Adding rows and columns makes me nervous. Isn't the idea to uniquely
identify a cell? Is 5+3 different than 3+5? I would expect to see a
muilitply in there too.
[...]

Your nervousness is understandable, but in this case I think adding
the row and the column is actually sensible. The program attempts to
indicate whether a given square on a chessboard is black or white.
The square at row 5, column 3 is the same color as the one at row 3,
column 5.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 26 '06 #8
On Tue, 2006-26-09 at 18:59 +0000, Christopher Benson-Manica wrote:
anand devarajan <is**********@gmail.comwrote:
>[bad code]
#include <stdio.h>
#include <math.h>

int main(void)
{
int row,result,col;
printf("enter the row\n");
scanf("%d",&row);
printf("enter the col\n");
scanf("%d",&col);
result=row+col;
if(result<96||result>110)
printf("not valid");
else {
if(result%2==0)
printf("black\n");
else
printf("white\n");
}
return 0;
}

This obviously isn't correct, but a regular might now be willing to
attempt to help you. Examine the differences between your code and
this closely.

I've snipped the rest of your post, because it was unparseable.
Please write in English, like this. Usenet is not a text message
service.
I'll take the liberty of cleaning up the style somewhat (thanks for
making it readable, Chris :-)) I've also replaced some of his ASCII
assumptions with proper C. Finally, I marked all the lines that are
obviously spurious:

#include <stdio.h>
#include <ctype.h>
#include <math.h>

int main(void)
{
int row, result, col;
printf ("Enter the row: ");
scanf("%d", &row);
printf ("Enter the column: ");
scanf("%d", &col);

result = row + col; /* This line is spurious. */
if (!isalpha (result)) /* This line is spurious. */
fputs ("Not valid!", stderr);
else {
if (result % 2 == 0)
puts ("Black.");
else
puts ("White.");
}
return 0;
}
It's actually pretty obvious what it's supposed to do, now. The OP
should note the importance of formatting.

--
Andrew Poelstra <http://www.wpsoftware.net/projects/>

Sep 26 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.