C :: Separate Numbers Evenly Into 5 Arrays

Apr 7, 2013

I have a set range, say 10 to 100, and I'm trying to separate the numbers evenly into 5 arrays. So there are 90 numbers, how can I assign 10 - 27 to the first array and the next 18 numbers to the next array without creating separate loops for each one?

View 3 Replies


ADVERTISEMENT

C/C++ :: Splitting Numbers Into Separate Digits

Dec 24, 2012

C++ program to accept a value and split it digit by digit and display in name

E.g.: 123

>one two three

View 4 Replies View Related

C :: How To Subtract Evenly

Feb 20, 2015

how do I subtract this so that I use the smallest number of $20, $10, $5, and $1 to pay $93? The book tells me to "Divide the amount by 20 to determine the number of $20 bills needed, and then reduce the amount by the total value of the $20 bills. Repeat this for the other bill sizes."I think the part in bold throws me off. What IS the total value of the $20 bills if I use $93 as the example? Is it $80, the highest we can go with $20 bills? Is it 4, the number I got from 93/20 after cutting off the decimal places, also the total number of $20 bills I can use?

I know how to do it and can do it in real life. It's like, "Oh, I need to pay $93. So I use four $20 bills, which brings me to $80. Using one more would bring it to $100, which is too much. So now, I need to use a $10 bill, which brings it to $90. Oh, so now, I need to use three $1 bills, which brings me to $93."But how do I tell that to a computer? It seems like I would have to put some kind of limits on it, or string code lines together,Here is the code so far:

Code:

#include <stdio.h>int main(void)
{
int amount, twenty, ten, five, one;
printf ("Enter a dollar amount:
");
scanf ("%d", &amount);
}

[code]....

View 5 Replies View Related

C :: Read 15 Numbers And Display Each Number On Separate Line

Oct 21, 2014

Program to read in 15 numbers and display them as follows //each number on a separate line

Code:

# include <stdio.h>
# define MY_ARRAY 15
int main(){
int i ;
printf("please enter 15 numbers

[Code] ....

Error that i get from compiler:
Error E2062 array1.c 14: Invalid indirection in function main()
Error E2062 array1.c 19: Invalid indirection in function main()
both pointing to the separate "scanf"

View 6 Replies View Related

C++ :: Big Numbers In Arrays

Apr 17, 2014

I have to create three arrays. my first array is going to be a 20 digit number if not less. this also goes for my second array.

#include <iostream>
const int Size = 20;
int CreateArrays (int Digit, int DigitArray[Size]);
void DisplayArrayEquation ( int Array1[Size], int Array2[Size], int ArraySum[Size]);
using namespace std;
int main(){
int Digit1, Digit2, DigitSum;

[Code] ......

View 17 Replies View Related

C :: Prime Numbers And Arrays

May 27, 2013

I was going through a book I have about C trying to learn about arrays, and one of the first few examples of what could been done with an array was showing how to use an array to generate a list of prime numbers. I've been staring at this program for about an hour trying to understand how it works (it does), but the workings of one for loop within the program.

Code:

#include <stdio.h>
#include <stdbool.h>
int main () {
int p, i, primes[50], primeIndex = 2;
bool isPrime;

[Code]...

So that is saying in order for this loop to go on, really two conditions must be met since there's that && operator. isPrime must be true (I think that's what it means by just having "isPrime" and not setting it equal to anything) and p / primes[i] must be greater than or equal to primes[i].So at the beginning of the loop, since i = 1, p = 5 (as per surrounding loop), and prime[i] = 3 ( as per the variable assignment at the beginning of the program ), the loop condition would be "isPrime && 5 / 3 >= 3"

"5 / 3 >= 3" The loop should stop right there! 1.666666667 is NOT greater than or equal to 3!

View 14 Replies View Related

C :: Add Two Big Integer Numbers Without Use Of Arrays

Dec 1, 2014

i'm having difficulty with a problem, i need to add two big numbers suchas 54646774456776 and another one 445556777554 and it would print the result. how can i approach this problem without the use of arrays?

View 4 Replies View Related

C++ :: Arrays Getting Random Numbers

Oct 30, 2013

Ok so Im suppose to make this program were the user inputs the size of the array then the user sets a certain range min and max for random numbers to be generated. I have a function named fillarray()

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int fillarray();

[Code] ....

Whenever i run the program i keep on getting a loop for the size of the array.

View 1 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++ :: Random Numbers Between 1 To 5 For Variable Of 5 Arrays

Sep 14, 2012

I want to have the random numbers between 1 to 5 for a variable of 5arrays. for having the random numbers i am using the code as below.

Code:
for(int i=1;i<=5;i++)
{ int j=rand()%5;
cout<<j<<endl;
}

The problem with this way of generating random number is that i get the same set of random numbers in every outputs. Is there any other way to have different random numbers with many different outcomes as much as possible.

View 7 Replies View Related

C++ :: Sorting Arrays - Int Numbers From Highest To Lowest

Oct 29, 2014

For my program i need to sort my int numbers [5] from highest to lowest but it seems that i made it go from lowest to highest ...

Code:

#include <iostream>
using namespace std;
int main() {
int numbers[5] = {3, -6, 10, 1, 130};
int counter1, counter2, tempNum;
//Highest to Lowest

[Code] ....

View 1 Replies View Related

C++ :: Program That Generates 5 Non Duplicate Numbers Between 1 And 20 By Using Arrays

Nov 4, 2014

program that generates 5 non duplicate numbers that is between 1 and 20 by using arrays. Here is my code and i cant compile it.

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
using namespace std;
int main() {
srand(time(NULL));

[Code]...

View 3 Replies View Related

Visual C++ :: Printing 2 Arrays With 10 Numbers Per Line

Jan 14, 2014

i got 2 arrays, how would i print 10 numbers per line, so that would be 5 numbers from each array.

array1[40];
array2[40];

array1 array2// array1 array2// array1 array2 // array1 array2 // array1 array2
array1 array2// array1 array2// array1 array2 // array1 array2 // array1 array2
array1 array2// array1 array2// array1 array2 // array1 array2 // array1 array2

...... and so on

how can i put this in a loop?

and so on but there are 80 elements so i cant go one by one.

View 5 Replies View Related

C :: Make A Separate Function

May 6, 2013

I will post the entire code at the bottom. Its running fine right now but This part in the menu function I need to make as a separate function. My problem is when I make it into a function by itself I have to declare and initialize the grades A,B,C,D,F how can I do that when I can't make them equal 0 because it has to keep track of how many of each letter grade.

Code:

//Count letter grade
if(ave >= 90)
++A;
else if (ave >= 80)
++B;
else if (ave >= 70)
++C;
else if (ave >= 60)
++D;
}

[code]....

View 3 Replies View Related

C++ :: How To Separate One Line Into Two (or More) Strings At The Tab

Nov 3, 2013

i'm reading from a text file which includes a dictionary in UTF8. it has the following structure:

word, bla "bla" translation

so there's a word and a translation seperated by tab. both can include any kind of charactars, excluding tab of course, especially blanks (found one code that claimed to seperate a string at tab, but also did at blank).

how can i seperate one line into two (or more) strings at the tab? i've been searching for a while, but can't find anything useful...

View 2 Replies View Related

C++ :: Objects / Classes And Separate Compilation

Apr 9, 2013

Code:
class A
{
public:A(int a, int b);
};

I need to have an object of class A that doesn't have a default constructor in another class, B:

Code:
class A; //This is in a separate header file
class B
{
private:A a;};

The problem is that it won't compile without a default constructor. I'm not allowed to define a default constructor, and the A object in class B has to be private so I can't initialize A a in public.

I also can't change the prototype in the interface to something like

A(int a = 0, int b = 0);

since one of the requirements is that if an object of class A is declared in main, it must not compile due to not having a default constructor. So what can I do to make class B work and compile?

Another question I have is why is this valid:

Code:
class A; //#include "A.h" is in the implementation file so it compiles.
class B
{
private:A* a;}; But not this: Code: class A;

class B
{
private:A a;};

This is for a project that I probably won't be able to turn in on time, but I care more about how to do this right than turning it in for full points.

View 4 Replies View Related

C++ :: How To Separate Login For Admin And User

Feb 2, 2014

How to compare the username and password entered by user with the data(username and password saved in before) in the admin array and customer array,

so for example when it match the username and password in the admin array, it will directs the user to the admin_mainmenu(), otherwise it directs to the customer_mainmenu().

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

char username_admin[10];
char password_admin[10];

[Code] ....

View 1 Replies View Related

C++ :: Returning Two Separate Variables In A Function?

Dec 12, 2013

How to use a function twice to calculate two different variables. How to have a function compute the city tax, then it uses the function a second time to compute the county tax.

My program compiles, and runs fine, however it only outputs the city tax calculation. It seems it never attempts to calculate the county tax.

One thing: All of the directives I used is what we are limited to, no more, no less. He requires a set format and will dock points of you use anything but those directives and void main().

Here is my code so far:

/* function for city tax calculation */

#include <iostream>
using namespace std;
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
const double city_tax_rate=0.03;

[Code] ....

I am using Visual studio 2010.

View 9 Replies View Related

C++ :: Separate Chaining Hash Table?

Nov 28, 2014

my insert() function

template <class T>
class Node
{
public:

[Code]....

View 6 Replies View Related

C++ :: Separate Template Class Into Two Files

Oct 13, 2014

I have a big big problem with class template

//file Array.h
#ifndef ARRAY_H_
#define ARRAY_H_
template <class T> class Array {

[Code] .....

I've tried many ways:
1. put #include<Array.cpp> at the end of file Array.h
2. Change Array.cpp to Array.hpp,...

But dont work at all

I have tried to separate class template into two files.

View 13 Replies View Related

C/C++ :: How To Separate Login For Admin And User

Feb 2, 2014

How to compare the username and password entered by user with the data(username and password saved in before) in the admin array and customer array,

so for example when it match the username and password in the admin array, it will directs the user to the admin_mainmenu(), otherwise it directs to the customer_mainmenu().

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
char username_admin[10];
char password_admin[10];

[Code] ....

View 2 Replies View Related

C/C++ :: How To Add Functions To Class In A Separate File

Jan 31, 2014

I could do the assignment if all i had to do was create a function within one file, call it in the main class, and that would be done with it. no, my teacher wants us to have our main program, a header and a separate class file and create functions in it in which we can then use in the main file.

This is the main file:

#include <iostream>
#include "call.h"
using namespace std;
int main() {
int length; //holds the length of the call in minutes
int hour; //holds the hour od the day(0-23 military time)

[Code] .....

View 7 Replies View Related

C/C++ :: Showing Separate Lines For Objects?

Mar 31, 2014

#include<iostream>
#include<string>
using namespace std;
//Constructors for class.
class CollegeCourse {
private:
int courseNum;

[Code] ....

When I debug my program, the objects is showing up on one line bunched up together. I also want to be able to enter data after each object of the classes.

The details of my project is as follows:

Inheritance in C++ means you can create classes that derive their attributes from existing Classes, in other words, a newly created class can absorb all the data fields and functions of a class already being used. When one class is derived from another, the original class is the parent class, base class, or sometimes called the parent class. The derived class is a child class, or sometimes called the subclass.

Inheritance is central to Object Oriented Programming. The advantages of inheritance are it allows the code to be reused as many times as needed. Inheritance also saves time and effort as the main code need not be written again.

Create a C++ program using Visual program that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates and uses objects of each class.

View 1 Replies View Related

C# :: ActiveX Control In Separate Thread

Jun 19, 2014

I have a method that does some extensive work (retrieves a list of emails from an imap server). What i wanted was to add a flash movie that would start playing when the method is entered and will stop when the method finishes. Something like this:

private void RetrieveMails() {
PlayFlashMovie();
RetrieveMailsFromServer{};
StopFlashMovie();
}

The flash movie plays, but the speed is horrible, almoust frame by frame (it actually matches the stepping of the foreach method that fetches the mails from the server as i can see it retrieving one mail - the movie plays one frame and stops; retrieves another mail - the movie plays another frame and stops.).

In the loop that retrieves the messages, i added Application.DoEvents(); so that is not the problem.

Now i am thinking of somehow playing that flash movie on a separate thread that will not hang synchronous with the retrieving mails loop but i don't know how would i do that...

View 2 Replies View Related

C :: Create Separate Array That Consists Of The Same Number

Mar 6, 2015

I working on a big program, and it involves character arrays. What I want my function to do is create a seperate array that consists of the same number of "*" as there are letters in the word from the text file. For example, if the word sarc was up, the function show make ****. This was my attempt at it. I managed to reach this far. I can only fit in one "*". This is part of jumble game program I'm trying to make, and its in C language.

insert Code: void partialWord(char current[]){
int n;
int i;
n = strlen(current);
for (i = 0; i < n; i++){
current[i] = strcpy(current,"*");
}
printf("%s
", current);
}

View 7 Replies View Related

C :: Splitting String Into Separate Characters Or Array

Feb 18, 2014

I have been looking everywhere, but the only place I have seen it done is Objective C. The Question: how do I split a string, input by the user, into an array of characters? No code shown because I know no commands that do this.

--Input by user as in fgets, or scanf().

View 2 Replies View Related







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