C++ :: How To Use Plus And Negative As Preprocessor Directives

Sep 21, 2014

how to use '+', '-', '*' as preprocessor directives??

I want to do the following work.

#define + 10
#define - 20
#define * 30

View 4 Replies


ADVERTISEMENT

Visual C++ :: Windows 64 Bit Or 32 Bit Preprocessor Directives?

Jul 1, 2013

I want to connect to an SQL Server database using ADO with VC++.

In order to do that you need to import an external dll, like so:

#import "C:Program Files (x86)Common FilesSystemadomsado15.dll"

What if the OS is not 64 bit? That would mean the (x86)-suffix would be incorrect.

how to work around this using certain preprocessor directives?

Something like this, maybe?:

#if 64bit
#import "C:Program Files (x86)Common FilesSystemadomsado15.dll"
#else
#import "C:Program FilesCommon FilesSystemadomsado15.dll"
#endif

View 9 Replies View Related

C++ :: Command Line Options For Preprocessor Directives

Oct 17, 2014

I want to run the following code from the command line:

Code:
#include <iostream>
using namespace std;

#ifdef ABC
const int num = 105;

[Code] ....

But I can not activate the ABC macro from the command line.

I'm trying to use the -d ABC option following the .exe file name, but I could not run the ABC macro.

How can I activate the ABC macro when I run the .exe file from the Windows 7 command line?

View 13 Replies View Related

C++ :: Having Negative 0 As Result After Multiplying Zero With Negative Number

Aug 27, 2014

Having error . I multiplied 0 by -4 and my result is -0 instead of 0. I tried to change the data type put It won't work. This is my code:

#include <iostream>
int main () {
double b, c;
std::cout<<"b: ";
std::cin>>b;
std::cout<<"c: ";
std::cin>>c;
std::cout<<b*c<<std::endl;
return 0;
}

View 2 Replies View Related

C :: How To Make The Preprocessor Compare Against Constants Defined

Mar 6, 2015

was just curios to know if there is a way to make the preprocessor compare against constants defined like this: Code: uint uint_max = -1;

View 1 Replies View Related

C++ :: Negative Numbers Not Working?

Jan 22, 2015

I have a program where the user inputs a line of numbers, and the two highest ones are displayed. It works fine, until negative values are entered at which point it shows 0 as the result.

Code: #include <iostream>
using namespace std;
int main( ) {
int num = 0;
int highest = 0;

[Code].....

View 6 Replies View Related

C :: How To Avoid Negative Output

Jul 12, 2013

I have a c program that I partially have working. The problem is basically writing a program that allows the user to input the amount of calories they plan to eat a meal and disperse the calories from top to bottom. My program produces the output in the example if I enter 1050 but the issue I noticed if the number of calories is just enough to cover the burgers I get negatives in the other variables.

For example, if I enter a total amount of calories of 1050, I can eat: Output: 2 burgers @ 770 calories (1050 - 770 = 280 calories remain) 1 bag of pretzles @ 170 calories (280 - 170 = 110 calories remain) 1 pear @ 80 calories (110 - 80 = 30 calories remain) 6 tsp. ketchup @ 30 calories If I input 1050 I get the above output but if I input a different integer such as 2000 this is my output 5 burgers @ 1925 calories 0 bag of pretzles @ 0 calories -1 apple @ -80 calories -35 tsp. ketchup @ -175 calories I can't give the full code since this assignment holds a lot of points and was up all night getting it work.

So I'll provide pseudocode

define all 4 variables burger 385, pretzel 170, pear 80, ketchup 5 print out text How many calories can you eat prompt user input
Divide user input into burger How many burgers can bet eaten subtract calories eaten from original user input
Divide calories left into pretzel How many bags can bet eaten subtract burger calories from pretzel calories
Divide calories left after preztel into pear How many pretzels can be eatn subtract pretzels calories from pear calories
Divide calories left over into ketchup how much ketchup can i use show on screen (int total)of burgers @ (int calorie total) calories show on screen (int total)bags of pretzels @ (int calorie total) calories show on screen (int total)pears @ (int calorie total) calories show on screen (int total)teaspoons of ketchup @ (int calorie total) calories

The problem I see is that subtracting the calories from the pear from the left over calories of the pretzel calories leads to a negative. If leftover calories minus 80(pear int) its less then 0 . The calculations from the pear onward to ketchup become incorrect resulting in negative output.

View 6 Replies View Related

C :: How To Define Negative Number

Sep 3, 2014

I nead to define an a negative number a normal posetive number i defined like #define RSSI_UP 1 can i write #define RSSI_DOWN -1???

View 2 Replies View Related

C++ :: Positive And Negative Infinity

May 2, 2013

What are positive and negative infinity for different data types in c++, are they represent maximum and minimum limit of a type? or positive infinity is not a finite value.can some explain this positive and negative infinity paradigm

View 3 Replies View Related

C++ :: Negative Number Check

Sep 30, 2013

The code on lines 44-53 is suppose to display a message when the user enter a negative number, however, when a correct positive number is entered the message is display again.

#include<iostream>
#include<cctype>
using namespace std;
int main() {
char carType;
int A, B, C;

[Code] ....

View 2 Replies View Related

C++ :: Display Negative Number?

Mar 12, 2014

I am getting strings from an HTTP request that will have hex values and I must convert those strings to a signed decimal.

//typical string inside response: //0E1D052BFBB711C1002C0042007A014DFE44022B270F7FFF8000000000000000
//every 4 characters above are a signed decimal value
for (a = 0; a <= 63; a+=4){
sprintf(vval,"0X%c%c%c%c",response[a],response[a+1],response[a+2],response[a+3]);
ds = strtol(vval, NULL, 16);
sprintf(vval,"%d",ds);
}

The problem is I never see a negative number. Decoding 0x8000 gives me 32768 but not -32768.

View 7 Replies View Related

C++ :: Time Measurement Returns Negative Value

Oct 9, 2013

I am using the first method, listed here.

I want to take the time measurement of a construction of a tree, which contains about 2841482 nodes (inner and leaves). Here it is:

Code:
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
Tree t(...);

clock_gettime(CLOCK_MONOTONIC, &end);

int64_t time;
time = timespecDiff(&end, &start);
std::cout<<"Time: " << time << " ns

"; which gives me always a negative value, like -13481628 ns.

View 9 Replies View Related

C :: Ignore Negative Numbers In Array

Feb 15, 2014

So i have this program that takes in user input and stores them into an array and then prints them, removes duplicates, and sorts in ascending order. The user can also stop by inputting a sentinel value (in this case -1). But i am also supposed to ignore any negative value besides -1. When i input any other negative value into the program it messes up. How would i go about ignoring the negative values?

Code:
#include<stdio.h>
int main()
{
int input, nums[20], i, j, k, temp, count=0, count2=0;
for(i=0;i<20;i++)

[Code] .....

View 8 Replies View Related

C :: How To Correctly Multiply With Negative Numbers

Jul 24, 2013

I've been working on this program to create a simple desk calculator for a school assignment, and I managed to finish. All we had to do was add, subtract, multiply, and divide positive integers - and I was able to do that just fine. This program got me thinking though, because I do not know how to write commands to multiply/divide negative numbers.

In fact, when I divide a number like 21 by 4, it comes out to 5 because I don't know how to allow it to compute remainders (which wasn't a requirement for my program). This intrigued me so I've been trying to figure it out for the last few days but to no avail. Here's my code:

Code: void flush_buffer(){
int ch;
while ((ch = getchar()) != '
' && ch != EOF);

[Code]....

And just know that my code works perfectly fine, I'm not here for troubleshooting it. I just want to know what I can change to allow negative values to be correctly computed.

View 12 Replies View Related

C :: How To Create A Program That Not Allow Negative Numbers

Sep 2, 2013

I have a homework assignment due that told me for the "input specification" that "n" is an integer greater then 0. How would I put this in and where?

View 1 Replies View Related

C :: Negative Numbers Are Biased In Two Complement?

Mar 2, 2014

I am reading one of the exercise solutions for C Programming Language: The C Programming Language Exercise 3-4

In it, it states that negative numbers are biased by (2^n - 1) (i.e. -I is represented by (2^n - 1) - (+I). So:

Code:
Bias = 2^8 - 1 = 255 = 11111111
Subtract 25 = 00011001
Equals = 11100110

what is meant by the "bias" here and what is the value of "I" here. It just suddenly uses "I" without explaining what it is.

View 4 Replies View Related

C :: Largest Negative Number In 2 Complement

Mar 3, 2014

In this exercise:The C Programming Language Exercise 3-4..It states the following: "In a two's complement number representation, our version of itoa does not handle the largest negative number, that is, the value of n equal to -(2 to the power (wordsize - 1)) ."

A char is one byte (255 bits). The range of an 8 bit variable using a two's complement representation is -128 to 127. Therefore -128 is the largest negative value. The statement in book suggests that the itoa function will not output -128 if we pass -128 as a parameter, because in itoa when we try to convert -128 to positive -128, the inverse of -128 is -128. However, I just ran this code in my computer and it successfully outputted -128.

Code:

#include <stdio.h>
#include <string.h>
#define SIZE 10
void reverse(char s[])
{
int c, i, j;
}

[code].....

View 2 Replies View Related

C :: Strcmp Negative Value From User Input

Jul 24, 2014

I am studying c and I thought what would be better than using my pi to play with relays and c. I am used to PHP as a scripting lang and don' t do much programming. So I wrote this to use wirepi and ask the user "on or off" they type on or off and it does it. it does work but I know something is wrong when I use strcmp in the if statment I can -10 for a value. Here is the code.....

Code:
#include <stdio.h>
#include <string.h>
main(int argc, const char * argv[]) {
char oo[100];
system("gpio mode 0 out");
printf("Do you want it on or off?

[Code] ....

This is what it outputs at the prompt

Do you want it on or off?
on
on

It is now on!

How can I just get Code: if (oo = on) {} and like so with off.

View 2 Replies View Related

C++ :: Positive Remainders Returning Negative?

Nov 26, 2013

int Fib1 = 1;
int Fib2 = 2;
int Fib3 = 0;
int randomynumber;
int Loop;

[code].....

this returns negative numbers sometimes.what did i do wrong side note this is not the complete program it is only the part with the problem because the complete code is sort of longish and very confusing

View 2 Replies View Related

C++ :: How To Convert A Negative Number Using Ntohl

Dec 6, 2013

I receive a negative number but in big endian order. ntohl seems work for unsigned only.

Is there a method for me to translate it back to the original negative number from big endian?

View 2 Replies View Related

C++ :: Ignoring Negative Values In Array?

Nov 8, 2014

I need to ignore negative values in an array, but not exit the function.

For example if the user enters:

1,2,3,4,-1,-2,0

the array would be

[1,2,3,4]

Is there a way to ignore these values?

View 1 Replies View Related

C/C++ :: Skips Loop Even Though Variable Is Not Negative

Jan 19, 2015

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
float rate, hours, overtime, tax_calculated;
float tax = .15;

[Code] ....

View 7 Replies View Related

C/C++ :: Counting Positive And Negative Numbers?

Jan 27, 2014

#include <iostream>
using namespace std;
int initialization (int []);
int identifying (int [],int);

[Code].....

View 8 Replies View Related

C/C++ :: Isdigit To Work With Negative Numbers

Jul 28, 2012

Ok well i know that isdigit in my code is seeing the negatives as a character and so i made my program give an error message. But i need negative numbers to work how could i get this to work with negative numbers.

The code is supposed to add the 3 numbers input into the command line argument including negative numbers.

#include <stdio.h>
#include <stdlib.h> 
#include <ctype.h>
#include <string.h>    
int main(int argc, char *argv[]){  
   int add=0;
   int i;
 
[Code] ...

View 2 Replies View Related

C++ :: Display Count Of Positive And Negative And Zero Entered

Aug 18, 2014

Write a program to enter the number till 100 till the user want and at the end it should display the count of positive and negative and zero entered.

View 8 Replies View Related

C :: Why Program Can't Subtract Negative Number From Positive One

Feb 2, 2015

My program uses a while loop to eventually get to an error of zero and a root of sqrt(3). I'm not understand why after the third iteration the program fails to compute a new x value. I'm using Visual Studio 2013. The code tag instructions were dubious.

Code:

#include <stdio.h>
#include <math.h>
main() {
/*This program uses the Newton-Raphson method to solve y = (x^3)-3 for it's roots.*/
printf("This program uses the Newton-Raphson method to solve y = (x^3)-3 for it's roots. Enter your estimate of the root.
");
float x,y,z;
int num;
num = 0;

[Code]...

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved