With an extra newline and space. How to get rid of it and print it on the same line.
I have checked that text does not include new line character at the end. Also, it seems to print correctly using cout, but not print correctly to output file...
For the last part of this problem, if player 2 loses the game of hangman, I need to display the letters they did get right. In order to do that, I believe that I need to traverse vector v for the elements that exist in the string hiddenword, and then print those characters that match.
1) Write a program that asks the user for a a single character and two XY coordinates. The two X and two Y values should all be integers between 0 and 50. The character should be a printable ASCII character with values between and including ' !' (ascii value 33) and '~' (ascii value 126).
2) Your program should then draw a rectangle made up of the user selected character where the upper left corner is at X1; Y 1 and the lower right corner is at X2; Y2. Be sure to print the appropriate number of blank lines (having spaces in the blank rows is OK) in the beginning and pad each row of your rectangle with X1 leading spaces.
The Output is supposed to be similar to this:
(X1,Y1) = (0,0) , (X2,Y2) = (4,4), the character = ^
^^^^ ^^^^ ^^^^ ^^^^
What I am having trouble understanding is printing between certain ASCII values (ASCII has never been discussed in class).
Another thing I am having trouble with is the main part of the assignment. From what we are currently discussing is loops and the assignment is covering nested loops. My code looks similar to this: Code:
#include <stdio.h> int main (void) { int X1, Y1, X2, Y2; char cRec; printf("Enter a character: "); scanf("%c", &cRec);
[Code] .....
My thinking on the assignment is that you want the X1 coordinate to increase to the value of X2 (same for Y1 and Y2). Is this thinking wrong?
I'd have to print the elements in italics. I've tried this:
for (i = 1; i < a.GetLength(0); i++) { for (j = i-1; j >=0; j--) Console.Write("{0,-2}", a[i, j]); Console.WriteLine(); }
with the array mentioned above but for some reason it keeps printing the elements BELOW the line, when I need it to print those above it. I know that for arrays we usually start loops with a value of 0 but seeing as there should be nothing to print at [0,0] I started the loop at 1.
I am trying to read hex data from a file (not just hex values in text format). I was able to read it (02 EC) with "fread" into an char before but I need to change the Hex value into an integer in decimal.
I already read about strtol but I would prefer reading the hex Value into an integer.
Here is my code so far:
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int itrack1[1]; int itrack2[1];
So I'm doing a kind of banking system. Atm I've got the user able to create an account and set the balance of it, which is written to a .txt file. However, I would like the user to be able to enter their account no. and the program to cout the account info on the screen. I will be adding more to the program later, but until I work out how to search for values in a .txt file, and print out values on that line I'm a bit stuck.
Code: Main.cpp - #include <iostream> #include "create_account.h" #include <fstream> using namespace std; int menuin; int main() { create_account creataccObj;
I want to add this piece of code to a project. I have created a vector from values entered by a user. I want to then subtract each value from each other from the beginning to the end. For example if a user enters 10,4,3 the program will subtract the values in that order 10 - 4 - 3 and output 3 as the solution. I figured how to do it with addition but can't get it to output for subtraction.
#include <iostream> #include <vector> using namespace std;
I'm trying to print values from a vector of a struct and I don't really know how to do that. Here is a simple code that I have for now to test how to add data to the vector then attempt to print it out.
#include <iostream> #include <vector> #include <string> #include <deque> #include <fstream> using namespace std; struct Employee//employee data
I have a class that uses std::vector. I push back class objects onto the vector but when I try to cout the data members (with get functions) I get garbage values.
Here is the class:
#ifndef JOBS_H #define JOBS_H #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; class Jobs{
[Code] ....
I know I am missing the implementation of several functions but I'm just testing my vector to see if it is working and it isn't. The getBlockValue() function should output 0 for each job. When I push back one object the output is 0. When I push back 2 objects the output is 0. However when I push back 3 objects I get random values. Why is this? I thought vectors were dynamic?
I am writing a program to play rock paper scissors, and I am trying to get a vector to store the result of a given round of play, and output it as a declaration as to who won. I can't figure out how to store the values in the vector properly, and how to use the vector as an argument to output the result of play.
I'm taking a C++ computer science course right now, and one of the questions on my latest assignment is this:
"A partition of an integer n is a way of writing n as a sum of positive integers. For example, for n=7, a partition is 1+1+5. Write a program that finds all the partitions of an integer n using r integers. For example, all the partitions of n=7 using r=3 integers are 1+1+5, 1+2+4, 1+3+3, 2+2+3."
I've been struggling with this problem for a couple days now, and how to do it. I understand I need a recursive function to grab variables, and probably an array or vector to store them, but where to begin.
I've been reading documents on partition generating and the concept still eludes me, and any other questions on here or other programming sites using partitions don't seem to have a constraint on them.
I am trying to seed a vector with 52 values ranging from 1 to 52. I already have the code written to seed the vector bu how to keep from repeating the same values from being seeded. This is for a five card stud game.
#include<iostream> #include<cmath> #include<cstdlib> #include<string> #include<vector> #include<ctime> using namespace std;
Now asking for streams. Calling getAvailableStreams. Giving so many streams: 2, 2 got so many streams: 0
Why am I getting 0 streams when I exist the method? I just had 2 streams in availableStreams while I was inside the method, where have they disappeared?
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:
I have a function that rotates a vector 90 degrees. Only problem is, i never get negative values. For some strange reason, no matter what i do, the value of x is positive. And even if the x is negative. Once i put it into direction (struct with 2 values x and y) it turns again to positive. Im using VSC++2013 ultimate. At first direction was SDL_Point, so i thought it was SDL problem, but now it seems its something else.
if (c == '-') { int x = direction.y; x *= -1; int y = direction.x; direction = { x, y }; }
Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.
I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?
Code: #include<stdio.h> #include<stdlib.h> #include<math.h> int main () {
I'm trying to get my program to read a series of comma delimited values from a file into a vector. However, I am unsure how to actually go about doing this. I've posted my best guess below but it's really just a stab in the dark and I always receive a compiler error.
How to output vector contents using the push_back function. My program reads in values just fine, but it does not output anything and I've been stuck on why.
here is my code:
#include <iostream> #include <array> #include <vector> using namespace std; int duplicate( vector < int > &vector1, const int value, const int counter)
I have a cpp app that reads in a number of files and writes revised output. The app doesn't seem to be able to open a file with a ' in the file name, such as,
N,N'-dimethylethylenediamine.mol
This is the function that opens the file :
Code: // opens mol file, reads in rows to string vector and returns vector vector<string> get_mol_file(string& filePath) { vector<string> mol_file; string new_mol_line; // create an input stream and open the mol file ifstream read_mol_input; read_mol_input.open( filePath.c_str() );
[Code] ....
The path to the file is passed as a cpp string and the c version is used to open the file. Do I need to handle this as a special case? It is possible that there could be " as well, parenthesis, etc.