C++ :: Will Overflows Loop Back Around And Become Positive Again?

Apr 24, 2012

If I have a positive double and cast it to an int. If it overflows, I know that most of the time, the value of the int becomes negative. If it overflows far enough, will it eventually become positive again?

Code:
double d = 34192384732194872394837249832743984738.;
int i = (int)d;
std::cout << i << std::endl;

Is there any value of d > INT_MAX that will cause i to be positive?

View 4 Replies


ADVERTISEMENT

C# :: Use Loop To Load Two Forms Back And Forth Then Stop At Loop 4

Feb 15, 2015

I have tried to submit this topic before but i didn't submit my whole code and it was removed. So here it is. All I am trying to do is load form2 from form1 then back to form1 from form2 for a certain number of times the get out of the loop. I am new to C-Sharp and it seems as though I cant seem to figure out a way to do this.

Here is form1 and form2 code. I have commented out a few things I have tried.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[Code]....

View 3 Replies View Related

C/C++ :: Compute Sum And Average Of All Positive Integers Using Loop

Oct 8, 2014

I got an assignment which asked me to create a program that asks user to input 10 numbers (positive and negative) integer. The program would be using loop to compute sum and average of all positive integers, the sum and average of negative numbers and the sum and average of all the number entered. But, the new problem is after I've entered all the number, the answer that the program gave me wasn't the answer that the program supposed to give. I don't know how to describe it, I would attach a picture and the code below:

#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
//Declaration
int x, value, sum, average, SumPositive, SumNegative, Positive, Negative;
float AveragePositive, AverageNegative;

[Code] .....

View 12 Replies View Related

C :: How To Loop Back To The Beginning Of Function

Oct 11, 2014

I am writing another program and I cannot find for the life of me how to loop the program back to the start of a function.

Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int choice;
char band1, band2, band3, band4;
printf ("This program calculates the resistor value based on the colours of the wire.
(enter the integer near the command)
");
printf ("What would you like to do?

[Code].....

This is my current iteration of the program. Obviously, I haven't finished writing the case 1 of the first switch, but for the other ones. I thought that return main would cause the program to loop back to the beginning after executing the case, but I see that it is not the case (pun not intended). Anyways, what would I have to insert to cause the program to loop again (other than for case 3)? And another question, why is it that in scanf in the first case, the program only accepts two characters before finishing?

View 4 Replies View Related

C/C++ :: How To Loop A Program Back To Beginning

Mar 4, 2014

I was asked by my teacher to create while loop for this, iv have completely for gotten how and all the tutorial that i have found show basic lopping.

#include <iostream>
#include <iomanip>
using namespace std;
void checkAnswers(char[], char[], int, int);
int main(int argc, const char * argv[]) {
int choice = 0;
const int num_question=20;
const int min_correct=15;
char answers[num_question] ={

[Code] ....

View 5 Replies View Related

C++ :: Calculate Average Of A Stream Of Positive Numbers - Loop Program?

Feb 25, 2013

Write a program that calculates the average of a stream of positive numbers. The user can enter as many positive numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, treat zero as a positive number, i.e., zero counts as a number that goes into the average. Of course, the negative number should not be part of the average. You must use a function to read in the numbers, keep track of the running sum and count, compute the average, and return the average to the main() function. Note that you must use a loop to do this, as you don't know how many numbers the user will enter ahead of time. I am having problem writing a loop program for it..

View 1 Replies View Related

C++ :: Guessing Game - How To Successfully Loop Back To The Beginning

Feb 5, 2015

So I'm making my first program w/ C++ and its a game guessing game. I've learned how to use booleans, chars, strings, if/else, loops, and input. Anything past that I dont know. I've gotten my game to work properly except for the fact that when you guess incorrectly, the program closes. I want the program to go to the beginning of the program again so the user can restart. So far i've gotten the loop to beginning thing to work but not well. It'll only repeat twice before closing again and it'll say the user got the wrong answer even if it was correct. Here's my code

#include <iostream>
#include <string>
#include <random>
#include<ctime>
using namespace std;

int game(){
string playerName;
int guess;

[Code] ....

View 1 Replies View Related

C++ :: Loop Program To Go Back Without Losing Values Of Variables?

Mar 30, 2014

I know that returning to main() is not a good idea but how will I loop the program to go back to the position selection when the voter is done voting for the last position.

when I run the program it seems fine. getting the votes from President to PRO Position is fine. The problem is how will the next voter vote without losing the vote (tally) of the previous voter?

FLOW:
SELECT POSITION (a-e) ---> SELECT A CANDIDATE (a-c) ---> (this goes on until the position of PRO) ---> ( then go back to the POSITION SELECTION)

After every vote there is a case statement for which I can choose to vote for the next position, quit, or show results (and after showing the results it will go to the next position to vote)....

#include<iostream>
#include<string>
#include <conio.h>
using namespace std;
int pca=0,pcb=0,pcc=0,ptv=0;

[Code] .....

View 1 Replies View Related

C/C++ :: Shifting Characters - How To Make Letters Loop Back To The Start

Feb 9, 2015

I have to make a function that i'll later be able to use for a ceasar cypher. The letters should shift a user inputted number. This is what I have so far:

char shiftChar(char c, int s) {
char ch = c;
int shift = s;
int newC;
newC = int(ch) + shift;
return newC;
}

The problem with this, is that it doesn't loop back to the start of the alphabet once i get past z.

View 2 Replies View Related

C :: Language Program Environment Does Nothing To Prevent Buffer Overflows

Sep 25, 2013

TheC language program environment does nothing to prevent buffer overflows ..... is there any pros to the obvious cons of this?

View 3 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 :: 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 :: Positive Binary Output Function

Mar 27, 2013

I have written a function that takes in a positive decimal and returns its Binary equivalent; however, the output always adds an additional zero to the binary. What could I do to get rid of it?

If the number is 7, it outputs 0111 instead of 111.

Code:
#include <stdio.h>
void Dec(int n) {
if(n > 0)
Dec(n/2);
printf("%i", n%2);

[Code] ....

View 2 Replies View Related

C :: Enter 10 Positive Numbers In Array

Nov 3, 2014

I have task to make program.. To enter 10 positive numbers in an array. Find three numbers that stand near each other and that have the maximum sum.

I understand how to make array, enter 10 number i find only one biggest number from 10.. How to find three max number sum that stand near each other..

View 10 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 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++ :: Passing Positive Numbers In Arrays

Nov 1, 2013

I am having an error at line 21. Specifically the code where it says "list[num]=x"

How am I able to fix this code to do what I want? The purpose of my program is to enter in positive numbers in an array (and having it end when 0 is typed) My program also accepts negative values but will ignore them when it is outputted. I believe I have all the code right except for line 21.

#include<iostream>
using namespace std;
const int ARRAY_SIZE(25);
void read_list(const int list[],const int ARRAY_SIZE);
int main() {
int list[ARRAY_SIZE];
read_list(list, ARRAY_SIZE);

[Code] ....

View 2 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/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 :: 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

C :: Program That Receives One Positive Integer And Display

Dec 28, 2013

Constructing this right aligned half pyramid? The code I had so far is right aligned and they're not in numbers

Write a program that receives one positive integer and display

_________ _ 1
________ 4 2
_______9 6 3
___16 12 8 4
25 20 15 10 5

when the user key in 5.PS: ignore the line

View 3 Replies View Related

C :: Function For Raising Numbers To Positive Integers

Sep 18, 2013

Write a function that raises an integer to a positive integer power. Call the function x_to_the_n taking two integer arguments x and n. Have the function return a long int, which represents the results of calculating x^n.Here's my code:

Code:

#include <stdio.h>
long int x_to_the_n(int x, int n)
{
int i;
long int acc = 1;

for(i = 1; i <= n; ++i)
acc *= x;
}

[code]...

It compiles OK, but when I run it the program stops after entering the number (x) and power (n).

View 2 Replies View Related

C :: How To Find Longest Series Of Even And Positive Numbers

Mar 6, 2015

Example input: 2 4 6 -1 7 3 -2 1

Output: 3 3 (longest series of even is 3, longest series of positive is 3)

Here is the code:

Code:

#include <stdio.h>
int even(int x) {
return x % 2 == 0;
}
int positive(int x) {
return x>0;

[Code]...

My question is how to write this code if the prototype of function is:

Code: void series(int *array, int n, int (*s)(int), int **begining, int *lenght);

View 1 Replies View Related

C/C++ :: Find Longest Series Of Even And Positive Numbers?

Mar 16, 2015

program:

Example input: 2 4 6 -1 7 3 -2 1
Output: 3 3 (longest series of even is 3, longest series of positive is 3)

Here is the code:

#include <stdio.h>
int even(int x) {
return x % 2 == 0;
}

[Code].....

My question is how to write this code if the prototype of function is:

void series(int *array, int n, int (*s)(int), int **beginning, int *length);

View 1 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







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