Freinds, I want some of you to help me write a program in 'C' to count the Total no. of +ves, total no of -ves and total no of zeros using ternary (Conditional Operaators). I am enclosing the Code fragment htat I have written. But it is giving a "Expression Syntax" Error.
#include <stdio.h>
#include <conio.h>
main()
{
int p, n, z, num, term, i, res ;
p = n = z = 0;
printf("Enter how many numbers you require? ");
scanf("%d",&term);
for (i = 1; i <=term; i++)
{
printf("Enter the number to check");
scanf("%d", &num);
if (num > 0 ? p = p + 1 : If (num < 0 ? n = n + 1 : z = z + 1));
}
printf("Positive numbers = %d\n", p);
printf("Negative numbers = %d\n", n);
printf("zero numbers = %d\n", z);
getch();
}
An Solution to this will be highly appreciated
1 1621 - if (num > 0 ? p = p + 1 : If (num < 0 ? n = n + 1 : z = z + 1));
This is probably where it goes wrong. Typically, if else statements are used instead of question mark and colons. The two following code fragments (should) generate the same code. - if(expr)
-
DoTrue();
-
else
-
DoFalse();
- (expr? DoTrue():DoFalse());
Therefore, either - if(num > 0)
-
p++;
-
else if (num < 0)
-
n++;
-
else
-
z++;
or
I'll confess I haven't used the ? : syntax in a long time, and usually it isn't used. I haven't tested the code, but I think it's correct. I know the if else code is.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Milk |
last post by:
Hi all,
Can anyone help me to do this Question. Coz this is my first time study C++
language and my lecture want me to do this kind of program, i really don't
have any ideal
pls help me
here...
|
by: Milk |
last post by:
Hi all,
Can anyone help me to do this Question. Coz this is my first time study C++
language and my lecture want me to do this kind of program, i really don't
have any ideal, or can send me some...
|
by: Mike |
last post by:
Hello,
I have a few rather urgent questions that I hope someone can help with (I
need to figure this out prior to a meeting tomorrow.) First, a bit of
background: The company I work for is...
|
by: samir dsf |
last post by:
hi
i thinks its a very strange problem.I had been running my file
ServerList2.aspx and i see the output(when i do f5). i am using this
file serverList2.aspx on hte left side of a main page (using...
|
by: |
last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I
keep getting the following error:-
Error In:...
|
by: comshiva |
last post by:
Hi all,
I have converted my existing ASP.NET project from 1.1 to 2.0 and i have
found that everything works fine except the linkbutton control in my
datagrid which throws an javascript error when...
|
by: SpiderSwamy |
last post by:
Hi,
I know little bit about asp, I am facing a problem in Validating
the ASP Form..
Example:
Stud ID: 501242016
FirstName: Ajit
LastName: Kar
|
by: ginnisharma1 |
last post by:
Hi All,
I am very new to C language and I got really big assignment in my
work.I am wondering if anyone can help me.........I need to port
compiler from unix to windows and compiler is written...
|
by: Hans Schneider |
last post by:
1. in the prg bellow what vars are stored on stack, heap, data segment?
int i;
void main()
{
int j;
int *k = (void *)malloc(1);
}
|
by: new to c |
last post by:
Hi!
I write the 2 codes
int i;
i = sizeof(long int);
printf("%i", i);
i = sizeof(int long);
printf("%i", i);
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |