C :: Determine How Many Numbers In A Range Are Divisible By Third - Loop

Mar 1, 2013

I've pretty much finished the entire program, except for the actual calculation part.

"Given a range of values determine how many integers within that range, including the end points, are multiples of a third value entered by the user. The user should be permitted to enter as many of these third values as desired and your output will be the sum of total multiples found."

I've defined functions to take user input for the low range, high range and a do-while loop to take as many third inputs as the user wants (terminated by entering -1, as requested by the question)

To actually calculate if they're divisible, I found out that if A%B = 0, then they are divisible, so I thought I would create a loop where each value in the range between A and B is checked against the third value to see if they output a zero.

What I need to end up with is a program that tells the user how many integers are divisible by the numbers in the range, i.e: "Enter the low range value: 335 Enter the high range value: 475 Enter a value to check within the range: 17 Enter a value to check within the range: -1 There are 8 total values that are divisible by the numbers in the range." Going back to my original question, how would I create a loop or something to "check" how many values are equal to zero, and consequently increment a variable for each instance? (This is how I think it should be done)

Code:

#include <stdio.h>
//GLOBAL DECLARATIONS
int getlowR();
int gethighR(int);

[Code].....

View 4 Replies


ADVERTISEMENT

C/C++ :: Odd Numbers Divisible By N

Apr 28, 2012

How to write a program of odd numbers divisible by n

View 1 Replies View Related

C :: Determine Number Of Binary Palindromes In Given Range?

Oct 26, 2013

Write a program to determine the number of binary palindromes in a given range [a;b]. A binary palindrome is a number whose binary representation is reading the same in either forward or reverse direction (leading zeros not accounted for). Example: the decimal number 5 (binary 101) is palindromic.

View 2 Replies View Related

C/C++ :: Program That Outputs Numbers Divisible By Two Values

May 2, 2012

A program that outputs all numbers divisible by both 5 and 6.This is what i have written :

#include<stdio.h>
int  main () { 
int i=200;
int b=10;
while(i<1000)
i b/6%==0
}

where could i have gone wrong.

View 1 Replies View Related

C++ :: Range Based For Loop In GCC 4.6.3

Apr 10, 2013

I would like to try out a range based for loop. I am using gcc 4.6.3. According to the link below, gcc 4.6.3 should allow me to use a range based for loop.

[URL]

However when attempting to run the code below, my IDE (Eclipse) reports the following error:

"error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options:

int a[5] ={1,2,3,4,5};
for (int x : a) {
cout<<x;
}

If gcc 4.6.3 supports range based for loops why do I get this error?

View 1 Replies View Related

C++ :: How To Determine If Two Numbers Differ From A Specific Value

Dec 2, 2014

I have to write a program that use a while loop and that each time around the loop reads two double, prints out the largest, the smallest and if they are equal.

I have no problem with this program but I can't understand how to modify it following the author : Change the program so that it writes out "the numbers are almost equal" after writing out which is the larger and the smaller if the two numbers differ by less than 1.0/100.

for now this is my code :

int main() {
double a = 0;
double b = 0;
while (cin >> a >> b) {
cout << "first number is : " << a << "
second number is : " << b << "

[Code] ....

The problem is that I don't know how to test if the numbers differ by less than 0.01 because my if statement doesn't work in any case. If I enter 2 and 1.99 It doesn't work, why ?

View 4 Replies View Related

C++ :: Reset Range Based For Loop

Apr 23, 2014

In the traditional for loop, you could make the loop start again by resetting the int value

for (int i = 0; i < 10: ++i){
//Do something
i =0;
}

Then it would start the loop again. However I can not seem to find a way to do this with the range based for loop. Is there anyway to force a range based for loop to start from, i = 0 ?

for(const auto &i : vec){
//Do something
//Restart for loop
}

View 9 Replies View Related

C++ :: Function To Determine And Print Prime Numbers

Mar 30, 2013

/* Task: create a function that determines prime number and use it to print out prime numbers from 0-50: */

Function prototype: Should return a `bool` (because it answers a yes/no question) and should take in a single int (to ask whether it's prime).

- An int greater than 2 is prime if it is not divisible by any number between 2 and itself, not including itself.
- Use this function to print out the primes less than 50. Check it against my list:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47

#include <iostream>
using namespace std;
int prime(int&x) {
if(x%2==1)

[Code] ....

It is printing out the correct prime numbers but also printing this between each number: 1629974960

View 3 Replies View Related

C++ ::  String Subscript Out Of Range / For Loop Conditions All Look Good

Apr 4, 2014

Im having a problem with my sneaky hangman game I feel like im really close just getting an error I can't fix. When I run it, it says something like string subscript out of range when I goggled it. it says im searching past the bounds of what it should be or something.

Also a dictionary.txt file is needed to run the program

code: [URL]

#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int guessesUsed = 0;
int wordlength;

[code]....

View 3 Replies View Related

C++ :: Random Numbers Are Not In Specified Range

Nov 9, 2014

My program behaves weird... I wanted to generate 10 random numbers from 1 to 100 each of them bigger than previous, using the while loop and function that returns a random number in specified range.

When I run the program, I get numbers much bigger than 100, even negative number, and numbers are same every time I run the program.

Code:
#include <ctime>#include <cstdlib>
#include <iostream>
using namespace std;
int range(int low, int high);

[Code] .....

View 2 Replies View Related

C++ :: Prime Numbers In A Given Range

Feb 17, 2013

I have an assignment where I have to use two for loops. I need to ask the user for any two numbers and be able to list all the numbers in between and their factors and state whether or not the number is prime or not.

View 2 Replies View Related

C++ :: Finding A Range Between 2 Numbers?

Sep 23, 2013

Ok so I'm reading the Programming: Principles and Practice using C++ and Im stuck in Drill 4 part 5. It says:

Change the program so that it writes out the "numbers are almost equal" after writing out which is the larger and the smaller if the two numbers differ by less than 1.0/10000000

I'm using an If statement for it... I just need know what the formula is to check 2 numbers that were entered by person if they land within the range specified above. so then I can cout << "numbers are almost equal" << endl;

View 4 Replies View Related

C :: Validation Loop - Displays Error Message When Input Is Outside The Range

May 14, 2013

I am trying to get this simple validation loop to work so that it only displays the error message when the input is outside the range 1-3. yet it always seems to display the message.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int Menu ();
int ValidInt(int , int );

[Code] ....

View 5 Replies View Related

C :: Calculate Prime Numbers In Range And Return Count Of Prime Numbers

Apr 28, 2013

I wrote a program which sends a starting and ending range to other processes and the processes calculate the prime numbers in that range and return the count of prime numbers to the head process, process 0. But this is not working properly at the moment. I realize I still have to split up the range based on how many processes I have...I still have not figured out how I want to set that up. I

Code:

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
int isPrime(int num);
int main(int argc, char **argv){
}

[code]....

View 7 Replies View Related

C++ :: How To Make Array With A Range Of Numbers From 1 - 9 Only

Jan 29, 2013

I want to make an array with a range of number from 1-9 only. So if the user entered more than or less than the number indicated it will be error and ask the user to reinput the data. So far my code can be used to do so that if the user enter the number one by one... But if the user entered all the number in one shot the reentered value will be prompt to the back automatically for some reason...Let say 10,2,3,4 which was suppose to be 1,2,3,4 became 2,3,4,1 instead... here is the code:

#include<stdio.h>
void main() {
int num[4][4];
int row,col,x,y;
for(row=0;row<4;row++)

[Code] .....

View 3 Replies View Related

C++ :: Find All Prime Numbers In A Range

Oct 17, 2013

I am trying to create a program that lists all prime numbers within a range of two number. Why the below program isn't working?

#include <iostream>
using namespace std;
int main(){
int high_range;
int low_range;
int w;

[Code] .....

View 3 Replies View Related

C/C++ :: Finding Happy Numbers For A Given Range

Oct 5, 2014

I'm currently working on an assignment that finds all happy numbers for a given range. Such as 1- 10. My current code just isn't cutting it. I have to use a user defined function and return a bool value to main in order to output if the number is happy or if it sad. For some reason, I cannot get it to loop properly. the first number will be displayed correctly, but the second and third are just squares of the first number, instead of being squared by their single digits. I'm dividing by 10 to get the first number of the digit entered, then I'm using mod to get the remainder. One thing I did notice was that the num2 was putting a remainder of 30 for 130, and I'm not too sure what I need to do to change that, without affecting the whole program.

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdlib>
using namespace std;
Program calculates the bill for a user

[Code] ....

View 8 Replies View Related

C/C++ :: Get Double Random Numbers In Range From 0 To 1?

Apr 19, 2012

How to get double random numbers in the range from 0 to 1?

View 2 Replies View Related

C++ :: Program To Determine Slope Of A Line - Stuck On Commas When Entering Numbers

Jan 1, 2013

The program I have is from a tutorial where the user enters two points on a line, and then the program calculates the mid-point and slope.

I want to modify it from it's initial form so that co-ordinates can be input in (x,y) fashion. Right now the user has to enter the x-coordinate, enter a space, and then enter the y-coordinate (lame...)

I saw people using SStream and using that to either write functions to ignore the comma or similar things for converting one file into an array, but not quite what I am trying here.

// program to determine slope of a line

#include <ios>
#include <iostream>
#include <istream>
#include <limits>

using namespace std;
void myflush ( istream& in ) {

[Code] .....

View 2 Replies View Related

C++ :: Generate A List Of 200 Random Numbers - Determine Median / Mode And Average

Oct 24, 2013

I am just starting out programming and have an assignment due in the near future. the problem is I cant seem to figure it out. I started it already but got stuck cant seem to figure it out. Here is the assignment.

Create a program that will generate a list of 200 random numbers (ranging from 1-1000) and determine the medium, mode, and average of the list of numbers. Have the program display the original list ant then display the list in ascending and descending order on the screen.

View 2 Replies View Related

C :: GSL And OpenMP - Getting Random Numbers That Are Out Of Expected Range

May 2, 2013

I am trying to parallelize some of my code with OpenMP. When I switch to using multiple threads I start getting random numbers that are out of the expected range.

Here is a small example:

Code:
#include <stdio.h>
#include </usr/local/include/gsl/gsl_rng.h>
#include </usr/local/include/gsl/gsl_randist.h>
int main() {
int mySeed=0;
const gsl_rng_type *T;
T = gsl_rng_ranlxs2;
gsl_rng *r_1 ;

[Code] .....

gsl_rng_uniform should only output number in the range [0,1) but with multiple threads it outputs larger number as well.

View 2 Replies View Related

C :: Loading Array With Random Numbers Within A Range

Oct 5, 2013

How would i go about loading an array with random numbers with in a range. For example, loading an array of 500 elements with random numbers in the range of 50-100.

View 9 Replies View Related

C++ :: Generate Random Numbers Within Specific Range?

Jun 5, 2014

So, there has got to be an easier way to generate random numbers within a specific range. Here is the code that I have been using, for a range of 1-6:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

[Code]....

View 10 Replies View Related

C++ :: How To Randomly Select Uniform Value From Range Of Numbers

Dec 28, 2013

How do you randomly select a uniform value from a range of numbers?

View 1 Replies View Related

C++ :: Find Factors And Primes For A Range Of Numbers

Oct 9, 2014

I'm trying to write a program that will find all the factors and primes for a range of numbers. I have the inner loop working but I am having trouble writing the outer loop that will output the range of numbers instead of just finding the factors for one number.

int n1 = 0;
int n2;
int factor = 0;
cout << "Enter a starting number: ";
cin >> n1;
cout << "Enter a ending number: ";

[Code] ....

View 7 Replies View Related

C# :: Generating Unique Random Numbers In The Range

Apr 28, 2014

We had to generate random, unique numbers in the range [1,15]. But running the program for several times showed a bug: It wouldn't always generate a new number for every repeated number. I can't figure out the problem, especially since it works half the time and I can't figure out what's making it work some times and not others.

bool flag1 = true, flag2 = true, flag3 = true;
int i, j = 1;
int[] A = new int[11];
Random rnd = new Random();
A[0] = rnd.Next(1, 15);
Console.WriteLine("1. = " + A[0]);

[Code] .....

View 14 Replies View Related







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