C++ :: Constructing Random Text Generator - Final Output
Nov 26, 2013
I am constructing a random text generator and i am almost done i just need final output. Here is my coding
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
const int NUM_FRIENDS = 5;
[Code] ....
This is how the output is supposed to look like
Program Output
== Who Should I Text? ==
Enter seed
Enter friend 0
Enter friend 1
Enter friend 2
Enter friend 3
Enter friend 4
You should text: Cat
These other friends didn't make the cut:
Adam
Bill
Damion
Edward
I can't figure how to output the remaining names.
View 3 Replies
ADVERTISEMENT
Jan 28, 2015
I have a program that is reading six characters from a text file, swapping every other character(ABCD would read BADC), and then adjusting their value based on a user's adjusted value input. If the adjusted value is 5 then letter A becomes F.
The final output line should print the initial six characters followed by the final six characters after the swap and encrypt adjustment.
I can only manage to print the final characters. Am I far off thinking I need to use pointers to point to the original character values?
One more thing: instructor wants us to complete this project as simply as possible meaning without the use of arrays, loops, switch statements, etc.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
//declarations
char c1,
[Code] ....
View 4 Replies
View Related
Aug 27, 2014
#include <stdio.h>
float total, avg, max, min;
float judge[4];
int index;
int array[4];
int main() {
total = 0.0;
max = array[0];
min = array[0];
[Code] ....
I dont understand how to make the array when it prints out only print out the final average and the final maximum score with the final minimum score but what its doing at the moment is just giving an average for each individual score taken...
Minimum and maximum scores are displaying 0.0
And it displays these things 4 times in a row i just want it to be displayed once.
View 1 Replies
View Related
Jun 19, 2014
I am working with a new text adventure. The way i want to construct it is by having a class for all living things. in the class you have basic things as: health, gold, vector for inventory holding "struct item". etc...
There is also a class called world, wich navigates through the world.
World class contains of: player location, and a map containing info about the room etc...
Here comes the problem. I want there to be characters to be placed out in different maps, so basically i want the world class to hold objects from Character.
How to do it. In world class i made a map...
std::map<int,"content">
content is a struct i made above in world class:
struct content{
std::string name; // location name
std::string info; // info about location
std::vector<Character>characters;
std::vector<item>items;
};
To sum it up, i have a std::map<int,content>map the int stands for location id. Content holds more info about the room and what's in it
btw the classes are in different files and that means i have to include "Character.h" in the world file so i can set up the vector of characters.
View 2 Replies
View Related
Jun 3, 2014
I'm trying to use a random response generator. I found a ton of information on this site, and I'm running a (very simple) program that is using 5 responses. My issue is, that every time I run the program (debug in visual express), it generates the same responses, in the same order, every time.
#include <iostream>
#include <string>
using namespace std;
int main() {
string mystr;
cout << "Hello. How are you today?
[Code] .....
View 4 Replies
View Related
Apr 1, 2014
#include<iostream>
#include<cstdlib>
using namespace std;
int main() {
char *article[5] = { "the", "a", "one", "some", "any" };
char *noun[5] = { "boy", "girl", "dog", "town", "car" };
[Code] ......
View 4 Replies
View Related
Feb 3, 2013
I have a class the generates a random number, do I put the radom generator function in the .h or .ccp file?
View 1 Replies
View Related
May 27, 2014
I have a random number generator that should genetate 2 numbers between 100 and 0. The first number works fine but the second doesn't, why?
i1 = random() %100;
i2 = random() %100;
while(i1 < 0 && i1 > 100){
if (i1 < 0)
i1 = i1 + random() %100;
if (i1 > 100)
[Code] .....
View 16 Replies
View Related
Apr 6, 2013
Write a program that generates an array of 20 random numbers between 1 and 100. Use a loop to output the numbers on the screen with a field width of 4 characters. Write code that will reverse the numbers in the array and then output the numbers to the screen with a copy of the same output loop used with the original numbers.
View 7 Replies
View Related
Feb 23, 2015
The program has two array of character. One of them has size 26 and is initialized with the alphabet a to z. A random number generator generates two numbers and these two numbers are used to index into this array of alphabets. The second array is used to hold the indexed alphabets. For example, the first row is the value held in the second array and the second row are the two generated numbers.
b g c z k e <- letter index by generate number n1=1 n2=6 n1=2 n2=25 n1=10 … … … … n2=4 <- generated n1 & n2
Please see illustration below for clarification on the above question.
Element a b c ……… x y z
Index 0 1 2 ……… 23 24 25
Array2
Element a b c ……… x y z
Index 0 1 2 ……… 23 24 25
Final state after program execution
Array1
Element a b c ……… x y z
Index 0 1 2 ……… 23 24 25
Array2*
Element c e m ……… z f g
Index 0 1 2 ……… 23 24 25
Random No generated 2 4 12 ……… 25 5 6
* Actual char element allocated to each index location will depend on corresponding random number generated. Program completes execution after filling all 26 locations in Array2.
View 19 Replies
View Related
Aug 4, 2013
How to produce a code that will satisfy the following constraints. I don't really know C++
- Produces a random three number positive integer between 001 - 504.
- Changes the output number every 24 hours on a website.
View 2 Replies
View Related
Oct 21, 2014
It seems as though my program is working great but I'm having problems with my random number generator. It keeps giving me a return value from the computer of scissors (or 3) for the computers random choice. What can I do?
//Purpose of Program: This program is meant to prompt the user to choose between 4 menu options.
// Each option will be the users choice of rock, paper, or scissors.
// the computer will then randomly generate a number and pit you against the computer.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void user(int getUserChoice);
void comp(int getComputerChoice);
void winner(int UserChoice, int ComputerChoice);
[Code] ....
View 1 Replies
View Related
Mar 5, 2014
How would I go about creating a random number generator (or pseduorandom I suppose) with user inputted lower and upper bounds along with a user inputted size of the sequence (so they can select how many random numbers they'd like outputted)?
View 3 Replies
View Related
Aug 28, 2013
I have to come up with a program that I have to create which is: The Computer guesses a random calculation "Value1 Operator Value2 = Answer." The computer randomly displays two of the four objects. The Player must guess the remaining two objects. If the player gets one right then the computer says "one is right." The game should continue until the user has provided all the correct calculations.
This is what I have, BUT I have 2 errors.
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
srand(static_cast<unsigned int>(time(0))); //Random Number Generator
double value1 = rand() % 50 + 1; //Random number between 1 and 50
[Code] .....
The errors I am getting in Visual Studio are:
error C2181: illegal else without matching if, line 212
IntelliSense: expected a statement, line 212
View 2 Replies
View Related
Oct 29, 2013
How would you code a simple random generator for dice rolling?
View 2 Replies
View Related
Jul 13, 2014
I am creating a random number generator and have run into a problem with my do while loop. it continually prints one of the lines of output infinitely. what am i missing here?
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
unsigned seed = time(0);
[code]...
View 7 Replies
View Related
Nov 15, 2013
I've been working on a program on and off for around a week now and I've been struggling towards the end of the program.First of all, the program is a maths quiz which generates two random numbers per question.I'll give you one part of my code:
Code:
srand ( time(NULL) ); //seeds the random number generator
int score = 0;
int a = rand()%12 +1; //generates a random num between 1-12
int b = rand()%12 +1;
int c = a+b;
int d;
}
[code]....
I've basically copied the above code 10 times and changed the variables by going through the alphabet e.g.
Code:
int a = rand()%12 +1; //generates a random num between 1-12
int b = rand()%12 +1;
int c = a+b;
int d; all the way to
Code:
int an = rand()%12 +1;
int ao = rand()%12 +1;
int ap = rand()%12 +1;
int aq = an+ao-ap;
int ar;
Now what I'm going to do is remove all the declared variables and create a loop. But my problem is; If I wanted to declare four variables for e.g.
Code:
int a = rand()%12 +1;
int b = rand()%12 +1;
int c = rand()%12 +1;
int d = a+b-c;
Would I place the srand( time(NULL)); inside the loop? it's confusing because I know an example of a basic loop with an array would be:
Code:
#include <stdio.h>
#include <conio.h>
int main(void)
{
int test[5]={21,18,47,21,4};
int I;
int total=0;
for (I=0;i<5;i++)
total += test[I];
}
[code]....
how or where to include the random number generator in the loop and to make it ask 10 questions at random.
View 1 Replies
View Related
Oct 25, 2013
I am trying to make a random number generator to simulate a critical hit if the number generated is from 0-critical amount. However, every time i run the code, despite being within the parameters set by the if statements, it always runs through as a critical hit and never a regular hit.
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
srand((unsigned)time(0));
[Code]...
There are four attempts to save time in getting a good result.
View 6 Replies
View Related
Aug 29, 2014
I was running some Monte carlo simulations and I was having some trouble passing my Normal-Random-Generating object as a parameter to the simulator.
I created a class called BoxMull which used the Box-Muller algo to generate Normal randoms and I based the Box-Muller algo on random numbers generated by the Mersenne-twister engine.
I am getting an error while compiling.
#include <iostream>
#include <random>
#include <cmath>
const double pi = 3.1428;
template<class rnd_gen>
class BoxMull
[Code] ....
View 6 Replies
View Related
Oct 15, 2014
I need to create a program that has has an array size of 20 and will generate 20 random numbers in it between 1-1000. Then I need to calculate the average of all the random numbers.
I have half of the code done ,but im lost on how to calculate the average of the random numbers.
Here what I have:
#include <iostream>
using namespace std;
int i;
int size[20];
int counter = 0;
int main() {
cout << "The Array Consists Of 20 Random Numbers: "<<endl<<endl;
[Code] ....
View 2 Replies
View Related
Sep 10, 2013
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++.
View 3 Replies
View Related
Feb 25, 2015
Looping a Nested If w/ random number generator
View 14 Replies
View Related
Nov 26, 2014
The user will be allowed to pick:
-the number of problems they want to do
-the type of problem (addition, subtraction, multiplication, division)
-the range of numbers for the problems (like 0 to 9, -100 to 100, etc.) [random numbers in the range]
Your program will then display the given number of problems and get the answer from the user. It will tell the user it they are correct or not. If they are incorrect, it will print the correct answer.
After the given number of problems are displayed, the program will give the user the final number correct and percentage correct. The user will be asked if they want to go again. If so, you will reprompt the user for all the information and run again.
I came up with code thinking I was going in the right direction but it doesn't work correctly at all. We have to use functions. My main issue is how do i call variables from another function so all of the functions work together. I repeat I don't understand parameters and calling functions. here's the code:
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int get_user_range(int &x, int &y);
int get_random_number ();
[Code]......
View 1 Replies
View Related
Apr 24, 2014
The user thinks of a number from 0 to 100 and the program tries to guess it. The problem is, I'm new to random numbers and use a function to generate them that isn't my own. It generates the same numbers each time the program runs, here are screen shots:
Run 1: [URL] .....
Run 2: [URL] .....
I read something about seeding or something, if I need it, must don't give me the answer. If you have the liberty of time explain more to me about the random business.
Here is my code:
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <unistd.h>
#include <string>
#include <ctime>
using namespace std;
int rand_lim(int limit) {
[Code] ....
View 4 Replies
View Related
Aug 9, 2012
I'm trying to create a program that creates random numbers. I looked through some examples and this is what I came up with. The time identifier seems to be undefined yet I see no reason it is undefined.
Code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
//Re-seed the random-number generator
time_t now;
[code]...
here's my error code..
1>------ Build started: Project: bake, Configuration: Debug Win32 ------
1> bake.cpp
1>c:usersjonbecherdocumentsvisual studio 2012projectsakeakeake.cpp(8): error C3861: 'time': identifier not found
1>c:usersjonbecherdocumentsvisual studio 2012projectsakeakeake.cpp(9): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
View 2 Replies
View Related
Mar 22, 2013
#include <iostream>
#include <stdlib.h>
using namespace std;
[Code]....
View 1 Replies
View Related