I'm coding a hangman game. I'm trying to store user entries so i can output them to show the user what they have already entered. Problem is that it's not display anything at all.
I'm trying to store multiple characters of course, and then display all characters stored.
My program is designed to read input from the user and then store that input in a structure variable. Whenever i use the cin.getline() function, it comes up with a semantic issue. Here is the code:
I'm trying to make a c++ program of this but i don't know how to use the bubble sorting.
Write a C++ application that asks the user to enter 10 numbers. The program then stores those numbers in an Array. The program should display the Mean , Median, and Mode.
Mean is the average of the 10 numbers. Median is the average of the 5th and the 6th numbers. (But you have to arrange the numbers in ascending order first using Bubble Sort before calculating the Median.) Mode is the most frequent number among the 10 numbers.
I'm trying to increment the values in a vector, not the vector size, based on variable input. Basically I have a vector of size 10, and all of its values are initialized at zero. The program counts the frequency of numbers 0-9 in a four digit user input. This is what I have (I want it to work so badly but the compiler says that I'm using a pointer to a function used in arithmetic):
for (int i=0; i < num_slots; ++i) { ++guess_frequency[guess[i]]; }
I just want to know if you can increment values within a vector:
What do I put to have UserNumber == 1-10? In other words I want it to say...
if UserNumber equals 1 through 10 <<<<This is where I'm having the issue.
Do this Else Do this
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Start: Console.WriteLine("Please enter a number between 1 and 10"); int UserNumber = int.Parse(Console.ReadLine());
I am trying to set the width of the data values which the user will input when using the program but I don't know how to get it to show the values when I tryto set the width of the variables in a nice column .
I get so close, and then it seems my brain shuts down ... I need to write a program that outputs a histogram of student grades for an assignment. The program should input each student's grade as an integer and store the grade in a vector. Grades should be entered until the user enters -1 for a grade. The program should then scan through the vector and compute the histogram. In computing the histogram, the minimum value for a grade is 0, but your program should determine the maximum value entered by the user. Use a dynamic array to store the histogram. Output the histogram to the console. For example, if the input is:
20 30 4 20 30 30 -1
Then the output should be:
Number of 4’s: 1 Number of 20’s: 2 Number of 30’s: 3
I can't quite get my output to look like that:
/* This program will display the histogram of student grades for an assignment */ #include <iostream> #include <vector> #include <stdlib.h> #include <conio.h>
i don't understand why this program crash if i'll insert a number more of 5 times... i want to allocate dynamically a vector if the input of the user exceeds 5 times... this is the code:
Code:
#include <stdio.h> #include <stdlib.h> int main() { int * vettore, n; unsigned int len=1; }
So I have to make a program that allows the user to enter both positive and negative numbers and the program is suppose to calculate the sum of only the positive values while ignoring the negative values. Also it is to be a sentinel-controlled loop with a number ending the set of values.
I am working on a text based RPG. As with most RPGs the character has attributes that grant modifiers. Lets take strength for instance. Suppose the character can have a strength score that ranges from 1 to 10. Based on strength the modifiers could be like the following:
Strength = 1 grants +1 to hit and +1 damage Strength = 2 grants +1 to hit and +2 damage Strength = 3 grants +2 to hit and +3 damage
I want to set these values at design time and be able to retrieve the modifiers based on the strength value from multiple places in my program.
What is the best method of designing this. I looked around online and saw references to Lists with Tuples and Dictionaries with Tuples but these did not seem to be a very efficient way of handling the scenario above.
I am having trouble with parsing out string value into a 2D vector. Suppose i have the string "attack at dawn " consisting of 15 characters, i will like to store it into a 2D vector with 5 rows and 3 columns and the result is as follow.
Vector[0][0] = "a" Vector[0][1] = "t" Vector[0][2] = "t" Vector[1][0] = "a" Vector[1][1] = "c"
I am currently trying to implement a 2d vector to store x and y of type int.
I have successfully passed it to the function, however i am unable to store the values in it. It always returns with a segmentation fault and my program terminates from there. May i know how do i store them properly and call them out?
Below is my code snippet
int reconstructSecret(int x, int y, vector< vector<int> > &inVec ,int constructSecret) { int getX,getY,formula,accum,count,getSecret,startPosition,nextPosition,numerator,denominator; getX=x; getY=y; int result;
[Code] .....
The main method
vector< vector<int> > inVec; for(int i=0;i<constructSecret;i++) { cout<<"please key in the "<<i<< "share of x value:"; cin>>x;
I am having trouble with parsing out string value into a 2D vector. Suppose I have the string "attack at dawn " consisting of 15 characters, i will like to store it into a 2D vector with 5 rows and 3 columns and the result is as follow.
Vector[0][0] = "a" Vector[0][1] = "t" Vector[0][2] = "t" Vector[1][0] = "a" Vector[1][1] = "c" Vector[1][2] = "k" Vector[2][0] = " " Vector[2][1] = "a" Vector[2][2] = "t" etc...
Here is a draft code that i did but is not working as desired.
vector<vector <string > > plaintextVector; vector<string> row; string totalString = "attack at dawn "; int dimension = 3;
I'm trying to read values from a file to store them in an array in C++ and then output the values in a table format for everyday of the month: morning, noon, evening and night. My text file looks something like this:
I just wanted to know how to store big numbers (like more than 20 digit values) in a variable?
For those type of big values, whether float variable is good or int variable is good?
And finally, all these challenges i am facing in the process of coding for an application which contains calculator and it should give the accurate results as our windows pc calculator.
I serialize a XML file, and i have this values here:
public class ServiceConfig { public List<DatabaseDescriptor> Databases { get; set; } } public class DatabaseDescriptor { [XmlElement("Name")]
[Code] ....
I have a form1 which is a datagrid view and get's updated like this:
dataGridView1.DataSource = xmlData.Databases;
Now i have a button: get tables, and it opens up form 2, there it's supposed to appear all the tables of the selected Database, when i click on the row i get the database name so i get all the list of Tables from
DatabaseDescriptor where DatabaseDescriptor.Name == name (I get this when i select the row)
But then on the 2nd form, i also have 2 textbox so i add a new table, i add the tablename and id. the new value should appear in the datagridview of the tables, and when i close it and reopen it, it should be there. Maybe i should concatenate first the values or something, how do i do?
Overview of problem : I am using std::vector to hold objects of Subject. Now this vector contains lots of objects( with lots I mean 10-20 objects at max) . These objects have string member values like category and sub_category. Both category and sub_category can have string which can be same of other objects's sub_category & category.
Issue: Now I want my std::vector to have only those objects whose's sub_category are unique. If category is not unique that's not a problem .
Secondly if we found 2 objects having same sub_category then we have to delete one of them from the vector. we will delete it based on some rules example
Rules for deleting are if
i) instance of Subject ->category = " Land " OR if category = "Jungle" then delete other duplicate object , ii) if above condition doesn't match then delete either of them.
I am wondering , how would I compare the sub-items from the vector . For example. I have class say Subject
class Subject { public : // some constructors, // functions to get ., set category and sub category std::String get_sub_category() std::string get_category(); private: std::string category; std::string sub_category; }
I have vector which stores object of Subjects. Example : vector<Subject> copy_vector;
Now what I want is to delete the object from vector that has same sub_category I am not looking for source code buT i need a starting point,? Example:
copy_vector[0] = Animal object that has sub_category Tiger copy_vector [1] = Animal object with Lion as sub category copy_vector[2] = Forest object with sub_category Tiger
What I want is to based on some conditions(which I can do ) remove either Forest or Animal object containing Tiger. But for that how would I do comparison? I have written the function and have checked it.
std::vector< Subject >copy_vector; // copy_vector contains all the objects of Subject with redundant sub_category for( std::vector< Subject >::iterator ii = copy_vector.begin() ; ii != copy_vector.end() ; ++ii ) { sub_category = ii->get_sub_category();
You are to write a C++ program to generate random integers in the range [ LOW = 1, HIGH = 10000 ] and to store them in a vector < int > of size VEC_SIZE = 250. Then, sort the contents of the vector (in ascending order) and display it on stdout.
To sort the contents of a vector, use the sort ( ) function from the STL. In addition to the main ( ) routine, implement the following subroutines in your program:
• void genRndNums ( vector < int >& v ) : This routine generates VEC_SIZE integers and puts them in vector v. Initializes the random number generator (RNG) by calling the function srand ( ) with the seed value SEED = 1, and generates random integers by calling the function rand ( ).
• void printVec ( const vector < int >& v ) : This routine displays the contents of vector v on stdout, printing exactly NO_ITEMS = 12 numbers on a single line, except perhaps the last line. The sorted numbers need to be properly aligned on the output. For each printed number, allocate ITEM_W = 5 spaces on stdout.
Programming Notes:
• You are not allowed to use any I/O functions from the C library, such as scanf or printf. Instead, use the I/O functions from the C++ library, such as cin or cout. • Let v be a vector of integers, then the call: sort ( v.begin ( ), v.end ( ) ) sorts the elements of v in ascending order. The detailed description of the sort ( ) routine can be found on the course web site and in the course textbook. • Execute the srand ( ) function only once before generating the first random integer with the given seed value SEED. The rand ( ) function generates a random integer in the range [ 0, RAND_MAX ], where the constant value RAND_MAX is the largest random integer returned by the rand ( ) function and its value is system dependent. To normalize the return value to a value in the range [ LOW, HIGH ], execute: rand ( ) % ( HIGH – LOW + 1 ) + LOW.
I am trying to create a simple interface on console to allow to input some values to some variables. For ex:
int main() { double a = 1.5; double b = 2.5; double c = 3.5; string x;
[Code] ....
However, I want these three to display at the same time (now they display one by one), and in the console window I can move the cursor between input place of a, b and c with "arrow key" of keyboard.
It seem to store the entire line in userID including the ":". I want to ignore the ":"'s and store everything in between in respective varibles in the order specified above.
So first string in userID, then ignore the :, then second string in name, and ignore the next :, and so forth.