Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Write a C++ program using pattern to check number if it is positive or negative using Scope Resolution Operator?

+4 votes
asked Jul 6 by nhjhnhoiji (170 points)
Write a C++ program using pattern to check number if it is positive or negative using Scope Resolution Operator?

3 Answers

0 votes
answered Jul 7 by jhatu (140 points)
WHICH PATTERN??
0 votes
answered Jul 7 by Peter Minarik (34,450 points)

I guess, for patterns, they meant that a number follows a specific pattern (that should be followed by your code too).

First of all, you should clarify if this is for integral (no fractions) numbers or floating point (fractions included) numbers.

Normally a pattern for a number is this [sign][integral part][decimal sign][fractional part]. (There is also the scientific notation, e.g. 1.234e3, but let's not focus on that right now.)

  • A sign is a plus or minus sign.
  • Both the integral and factional part are only series of numbers [0-9]
  • Different regions may use different decimal signs. So this may be a variable (e.g. it can be a dot or a coma).

See the Scope Resolution Operator. That being said, I'm not sure why the use of the scope resolution operator is important here for this problem.

With this, you should be able to start your design and write your code. If you get stuck, please, post your existing solution so we can give you a hand.

Good luck!

0 votes
answered Jul 8 by Yash Khandelwal (140 points)
#include<stdio.h>

int main(){

int m;

scanf("%d",&m);

m>0?printf("m is positive"):printf("m is negative");

return 0;

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...