C++ :: Search User Input Number In Array Filled With Random Numbers
Nov 6, 2014
I need to create A program That makes a 12x10 Array Grid Filled With Random Numbers From 0-99.
Then I need To Allow The User To Input A Number Between 0-99 And Then The program will then search through the array and count how many of the users number there is inside the array.
Code:
#include <iostream>
using namespace std;
int main() {
int input;
int number;
int row=0;
int col=0;
int Array [12][10];
I need to write a function with an array parameter and an int parameter.
That array has to be filled with first 10 prime numbers that are exact or higher than the int parameter... and then i need an average value of those 10 prime numbers...
The problem is im not really sure how i should do the part to fill the array with prime numbers that are higher than that int?? So any code samples that does that would be really nice... (the average part shouldnt do much problems i think, so i only need for that array fill...)
Code: int avgprimearray (int higharray[], int somenumber){ }
So I have an issue with a homework assignment that I am coding. I am attempting to get a function to iterate through an array and search for a number that was stored in an array by the user. So far I can take the number, get the numbers displayed but in my menuChoice2 function, for some reason the program is not confirming whether or not the number is entered, and is only telling me that the number has not been found, instead of confirming that the number is in the array.
Here is my code thusfar:
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> // Variables that are Globally declared int menuChoice = 0; int usernum[1000] = { ' ' };
[Code] .....
To be clear I am not getting any errors but something is telling me that the error is in the formatting of menuChoice2.
If the user puts in a 6. I need the array to display the even number from 0 - 6. Right now what it does is it displays the first six even numbers. Okay as I'm writing this I'm starting to see where my problem might be..
Code: void sumIntegers () { int arr[50]; int i = 0; int num = 0; int sum = 0;
i was trying to solve a problem in SPOJ and what i wanted to do is to accept an input number from the user and to convert it into a array of integer.
Code:
#include<stdio.h> int * toarray(int *num); int main(void) { int testCases; }
[code]....
But whenever i try to print the array in the main function i get only two value and the rest address
Code:
1//number of testCases 23456 //input number 6 2293452 4 2293700 1974439125
Process returned 0 (0x0) execution time : 4.152 s Press any key to continue. However, if i tried to print the array from within the function, it prints the numbers just fine.
print the array elements from the main program, so that i would be able to go on with the rest of it
I am having a problem printing out the results for my code, It is supposed to print out the largest and smallest value in the array, but keeps giving me a value not entered and I don't know why.
//This program lets the user enter 10 numbers and then display the highest and lowest number.
#include <iostream> #include<stdio.h> using namespace std; int main() { const int NUM_ENTERED = 9; int number[NUM_ENTERED], highestValue = number[0], lowestValue = number[0], count=0;
The textfile babynames.txt, which is included in the books website, contains a list of the 1000 most popular baby names of boys and girls. Write a program that allows the user to input a name and the program should then read the file and search the matching names among the boys and the girls. If the name is found it should output the name and the names rank. It should also indicate if their is no match. How to start this.
How to get this thing to work. All i need to do is ask user to input a name and then it brings out the line from the .txt file containing the information.
For example in my case I'm doing a member search function I'm required to ask user to input the name of the customer and then print out all the details (which consumes 1 text line in the .txt file)
Here is the code, This is the write to text file method (100% working)
I want to program a program that produces a random number between 1-10, then if the number is correct, says like HEY GOOD JOB and if its not says try AGAIN! also, at any point the user can quit by typing in X.
I know that I can use stuff like cout << "Hey put in a guess now" to prompt the user but I dont know how to accept inputs.
For example, how do I use scanf to do this?
I know that if I use scanf, it takes in a value, but where the heck does it store it?
eg. scanf(%s,guess);
Is that valid? I get an invalid expression error when trying to use that in C++.
Not a major issue since I got this to work but for some reason both my random numbers are the same and not sure why ...
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class ComputerAssistedInstructions { private static Random rand1 = new Random(); private static Random rand2 = new Random();
I can't compile this code as I am at work and the computers are security protected, So i''l have to wait until i get home to test this, but I am pretty sure I am wrong. The problem is I have to create two vectors with 10 elements and input random numbers into it, then pick one of the elements of the second vector at random and append it to an element from the first vector at random. This has to be done 10 times and the I am assuming i have to print the 10 results. This is what I have:
#include <cstdlib> #include <ctime> #include <iostream> using namespace std; int main() { vector<int> random (10);
I need my program to read a list of numbers from and input file, random.txt, and calculate the following statistics on those numbers:
A. The number of numbers in the file. B. The sum of all the numbers in the file. C. The average of all the numbers in the file. D. The largest number in the file. E. The smallest number in the file.
I have a partially filled array and I want to put that into a text file. Say I don't know how partially filled it is. How would I stop at the very end of the array where it has the last amount of data.
ex. int array[9] = {1,2,5,6}; ofstream output("txt file"); for(int i = 0;i < 9; i++){ output << array[i] }
How would I stop as soon as i becomes 4 because that is when the array stops?
I wrote a code which checks if there are any single numbers in an array.e.g.In the next array there is a single number - "3" 4 1 4 3 4 1..Here is an array which doesn't have single numbers in it: 4 1 4 3 3 1
Code: #include <iostream> using namespace std; int single (int arr[], int size) { int couple=0;
[Code]....
First I thought to double the number of couples I'll get from my search and find some connection to the length of the array, but it hasn't worked out (signed red).
Now i got here a program that asks the user to input 2 numbers if the first inputed number is smaller than the second then show all even numbers from the range of the 1st inputed number till the 2nd inputed number, but if the first inputed number is greater than the second then display all odd numbers from the range of the 1st number till the 2nd.
now my question is how do i invert the odd numbers?(on the 2nd condition)
Code: #include<stdio.h> int main(void) { int i,a,b,x; printf("Enter two numbers"); printf(" First number:");
There's this program I'm trying to code where the user gives input of 2 values.
Sample :-
Value of X: 1234 Value of Y: 234567 Reversed value X: 4321 Reversed value of Y: 765432 New value as Z: 1223344567 (each number was taken in both X and Y)
Now the thing is I could do the reverse, and I've been trying to find out how.
Here's my code,
#include <iostream> using namespace std; int main(){ int x=0, y=0; int reverse_x=0; int reverse_y=0; int z = 0; int l;
[Code]....
What I thought about that area where I've put a comment on, I was wondering if I code a loop for the amount of times x gets divided by 10 until it becomes 0 and store it in the value, same thing for Y, and add the value together to get Z. But if that's how it is then how I could use that concept here.
There's this program I'm trying to code where the user gives input of 2 values.
Sample :- Value of X: 1234 Value of Y: 234567 Reversed value X: 4321 Reversed value of Y: 765432 New value as Z: 1223344567 (each number was taken in both X and Y) Now the thing is I could do the reverse, and I've been trying to find out how.
Here's my code,
#include <iostream> using namespace std; int main(){ int x=0, y=0; int reverse_x=0; int reverse_y=0; int z = 0; int l;
[Code]...
What I thought about that area where I've put a comment on, I was wondering if I code a loop for the amount of times x gets divided by 10 until it becomes 0 and store it in the value, same thing for Y, and add the value together to get Z. But if that's how it is I can't seem to really get that idea how I could use that concept here. I'm not really good with programming, fairly new at this.
//Finding prime numbers #include <iostream> using namespace std;
[Code]....
/*The program currently prints all the prime numbers up to n (For example, if 7 is entered, it prints out: 1, 2, 3, 5, 7. What I want it to do, is print out the first 7 numbers; 1, 2, 3, 5, 7, 11, 13.
#include <iostream> #include <string> #include <limits> //for std: numeric limits #include <algorithm> //Function to get an integer from the user that is greater than or equal to zero.
int getPositiveIntFromUser(const std::string& prompt) { int retVal = -1;
[Code] ....
The first part works, but it doesn't calculate the GCD or LCM at all, it just crashes!