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


ADVERTISEMENT

C++ :: If Statement To Read Number Negative Or Positive Not Working

Nov 10, 2014

So I tried creating a test code for reading a negative number and positive number but whenever I enter a negative number it read it as being positive.

#include <stdio.h>
#include <iostream>
#include <iomanip>

[Code].....

PS: I am using char over int because the program that I am testing for requires me to use 8 bit variable.

View 2 Replies View Related

C :: Program To Show Highest Negative And Lowest Positive Temperature Of Year

Jan 19, 2014

I have an assigment and I don't know yet how to write this program :" I introduce the average monthly temperatures of a year(12 values for 12 months). When I compile the program it needs to show the highest negative temparature and the lowest positive temperature of that year.

Example: Entry data: -4 -6 0 5 10 20 24 25 17 8 -1 -7 exit data : max negative= -1 and min positive= 5 "

View 11 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++ :: 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/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++ :: 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 :: Finding Positive / Negative Integers Unsigned Can Hold

Jan 25, 2013

Consider a new data type, the mikesint, which can hold 9 bits.

(a) What is the largest integer that an unsigned mikesint can hold?
(b) What is the largest positive integer that a signed mikesint can hold?
(c) What is the largest negative integer that a signed mikesint can hold?

Not sure how to determine this. I'm stuck.

View 5 Replies View Related

C/C++ :: Transfer Array Values To Positive And Negative Arrays?

Oct 21, 2014

I have a problem with my assignment. I would like to ask how to transfer positive and negative values from array temperature to arrays positive and negative?

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int n=0, d=0, temperature[20], sum;
int positive[], negative[];
float avg;

[code]....

View 5 Replies View Related

C++ :: User Input - Calculate Sum Of Only Positive Values While Ignoring Negative Numbers

Jun 19, 2014

So I have to make a program that allows the user to enter both positive and negative numbers and the program is suppose to calculate the sum of only the positive values while ignoring the negative values. Also it is to be a sentinel-controlled loop with a number ending the set of values.

View 4 Replies View Related

C++ :: Recursive Function - Program Is Returning A Negative Number At The End

Nov 14, 2013

Why my program is returning a negative number at the end...attached is the program:

/*Write a recursive function recursiveMinimum that takes an integer array and the array size as arguments and returns the smallest element of the array. The function should stop processing and return when it receives an array of 1 element.*/

#include <stdio.h>
#include <time.h>
#include <iostream>
using namespace std;
float recursiveMinimum (int ARRAY[], int n);

[Code] .....

View 2 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++ :: Write Negative To One File And Positive Numbers To Another File

Dec 11, 2013

im supposed to create a program that reads in a list of integers from the terminal and writes the negative numbers to one file and the positive numbers to another file.

i got most of it doen but for some reason its not writting the negative numbers. on what im doing wrong?

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
int pos_num = 0;
int neg_num = 0;
int positive_numbers = pos_num % 5;

[Code]...

View 2 Replies View Related

C++ :: Average Negative / Positive Numbers And Total Average?

Nov 18, 2013

I am trying to average the negative numbers and positive number and of course the total average.

This will read in a list of n values, where n is not known ahead of time. The number of values read into the array will be saved in n.

vector<int> readList() {
std::vector<int> result;
ifstream inFile;
inFile.open("setA.txt");
for (int x; inFile >> x; ) {
result.push_back(x);

[code]....

array is a one-dimensional array of integers and n is the number of elements in that array that contain valid data values. Both of these are input parameters to the function. The function must calculate 1) the average of the n integers in array, storing the result in ave; 2) the average of the positive numbers (> 0), storing the result in avePos, and 3) the average of the negative numbers (< 0), storing the result in aveNeg.

void avgs (std::vector &array, int &ave, int &avePos, int &aveNeg) {
int sum = 0, pos_sum = 0, neg_sum = 0, pos_count = 0, neg_count = 0;
for (auto i : array) {
sum += i;
if (i > 0) { pos_sum += i; ++pos_count; }

[code]....

View 1 Replies View Related

Visual C++ :: Ignoring Negative Numbers When Trying To Add Only Positive Numbers?

May 15, 2013

ignoring negative numbers when I am trying to add up only positive numbers.

SAMPLE:
if (num>=0) {
sum= sum + num;
}
else

how would the else in this case being a negative number not be included in the sum

View 4 Replies View Related

C++ :: Program That Add / Subtract / Multiply Or Divide Two Integers - Incorrect Answers

Oct 7, 2012

Create a program that adds, subtracts, multiplies, or divides two integers. The program will need to get a letter (A for addition, S for subtractions, M for multiplication, or D for division) and two integers from the user. If the user enters an invalid letter, the program should display an appropriate error message before the program ends. If the letter is A (or a), the program should calculate and display the sum of both integers. If the letter is S (or s), the program should display the difference between both integers. When calculating the difference, always subtract the smaller number from the larger one. If the letter is M (or m), the program should display the product of both integers. If the letter is D (or d), the program should divide both integers, always dividing the larger number by the smaller one."

And here is the test data. I am posting the results from my desk-check table.

operation first integer second integer answer
A 10 20 30
a 45 15 60
S 65 50 15
s 7 13 6
G -1
M 10 20 200
d 45 15 3
d 50 100 2

Then, I transferred my program into a source file. Here it is:

//Exercise16.cpp - display answer of two integers

#include <iostream>
using namespace std;
int main() {
//declare variables
int firstInteger = 0;

[Code] ....

After putting in the data, everything worked fine, except the last two operations, which are M (multiplication) and D (division). All the answers for the last two operations essentially give me a 0.

View 4 Replies View Related

C :: How To Output The Last Positive Number Entered

Jan 25, 2014

Create a program that keeps on reading positive numbers until user enters a zero value, and then outputs the last positive number entered.

I do not know how to output the 'last positive number' and I do not even know am I doing things correctly so far....

Code:
#include <stdio.h>
int main() {
double num;
for(;;) {
printf("Enter a positive number: ");
scanf("%lf",&num);

[Code] ....

View 9 Replies View Related

C :: Unsigned Int Leads To Big Positive Number

Oct 29, 2014

I was going through the following statement in a c book:

"interpreting -1 as unsigned int leads to a big +ve number"

-1 is already unsigned .... then what does the above statement mean ??

View 3 Replies View Related

C++ :: Positive Number Divisible By 10 With No Remainder

May 3, 2014

Assume you want to make sure that the user enters a positive number that is divisible by 10 with no remainder. Write the condition you would use in the following do-while loop.

do {
cout << “Enter a positive number that is divisible by 10 with no remainder” << endl;
cin >> number;
}
while ( ____________________________________________________________);

View 2 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++ :: 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/C++ :: For Given 2D Array Count Number Of Positive Elements In Each Row Sum

Nov 20, 2012

#include <iostream>
using namespace std;
int main() {
    int h;
    double A[10][10];

[Code] .....

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++ :: 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++ :: Input From User A Positive Number N And Find Its Factorial

Oct 8, 2014

Write a C++ program that will input from the user a positive number n and find its factorial. Don’t forget to validate the input. The factorial of a positive integer n (denoted by n!) is defines as the product of the integers from 1 to n.

n! = 1* 2 * 3 * ... * (n - 1) * n

You should allow the user to continue working with your program for additional data sets.

Sample output:

Please enter a number: 5
5! = 120
Would you like to continue (Y/N)?Y
Please enter a number: 3
3! = 6

Would you like to continue (Y/N)?N
Good Bye!!

My code for what i think I'm doing is as follows:

#include <iostream>
using namespace std;
int main(){
int i=1;
int n;

[Code] ....

View 1 Replies View Related







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