C++ :: Read Sentences From User And Change Them Based On Their Character Choices
Sep 10, 2013
I'm trying to get the hang of the declaration and use of char. I'm trying to write a program that reads sentences from the user and changes them based on their character choices, I keep getting load of compiler errors.......am I off to a good start or am I way off?
#include<iostream>
#include<string>
#include<cstring>
#include<cctype>
using namespace std;
int main() {
char *quit*;
char sentance [100];
[Code] ....
View 3 Replies
ADVERTISEMENT
Jan 10, 2014
How to do this?
View 10 Replies
View Related
Nov 10, 2013
I have to optimize a code for below scenario. I am reading stdin (a file redirected to stdin) character by character. How many chars are going to come is not known. After every few chars there is a seaparator. e.g $ as below
rhhrkkj$hghjhdf$ddfkrjt
While reading, if the separator arrives I'm processing the string stored before that separator and then continue reading stdin in same fashion, till EOF. I am using getc(stdin) to read chars.
Using gprof I can see most of the program time is spent inside main() , for this reading logic. Rest of the program is just some insert and search operations. I am getting time of 0.01 secs at the moment, want to reduce further.
View 6 Replies
View Related
Aug 10, 2012
How do I write an a program that will read an input file character by character?
View 1 Replies
View Related
Feb 7, 2014
Player is given choice of x number of Races This choice changes the player's base stats. Then player is given a choice of x number of Classes (archer, warrior, etc.) This choice determines how the player's stats will change upon leveling up.
#include <cmath>
#include <iostream>
#include <ctime>
[Code]....
View 7 Replies
View Related
Oct 6, 2013
In my program, I'm supposed to read a text file (the name of which is given to me as a command line paramater, as long with an integer), and display the text in a specific format (each line can only be as long as the integer). However, I'm having trouble even reading the text file. I don't know the syntax. I'm only allowed to edit the function that does the formatting, and the code in that is
void typeset (int maxWidth, istream& documentIn)
I don't know how to 'read' the file, as most examples online are ifstream, or openFile or something like that. What I want to do is just read the first character of the file, and continuously keep reading characters until the end of the file.
View 10 Replies
View Related
Dec 6, 2014
I'm writing a Blackjack program where the user can choose to Hit(H) or Stand (S). I would like them to be able to use upper or lower case letter for this. My code doesn't seem to work right for my Stands.
Code:
char choice;
do {
choice = 0;
while (choice < 1) {
printf("
[Code] ....
View 3 Replies
View Related
Feb 19, 2015
I'm trying to determine the number of times I have to change each specific character in a string to make it a palindrome. You can only change a character one at a time from the end.
Example: "abc" -> "abb" -> "aba" should print 2. "aba" will print 0 because it's already a palindrome. "abcd" -> "abcc" -> "abcb" -> "abca" -> "abba" will print 4 because it took 4 changes to make a palindrome.
I'm not too sure how to approach this - I figured out the case where if it's a palindrome (if reversed string is the same) then it'll print out a 0.
int main() {
int number;
cin >> number; //expecting a number for first line user input
for (int i = 0; i < number; i++) {
string str;
[Code] ....
View 1 Replies
View Related
Dec 9, 2013
I am trying to fscanf a file and need to read the variable name 'f9' and 'a2' for example in the sample below and get their corresponding values '8' and '2' and then in my C program set the variables f9 and a2 accordingly (which I can declare as variables). Is this possible?
I making a Sudoku Solver and am thinking I would store the puzzle solution in a 2D array with a1=0, a2=1, etc... where 0, 1 are the array indices... then just print the array as the solution.
Note: The a1, a2, a3, etc... is my own numbering of the indices where the letter corresponds to the row and the number corresponds to the column (starting from 1) which I use when feeding to the solver.
I have a file that has the following format (output of Z3 SMT solver):
sat
(model
(define-fun f9 () Int
8)
(define-fun a2 () Int
2)
(define-fun c5 () Int
6)
)
View 1 Replies
View Related
Apr 17, 2014
I am doing an assignment that is to calculate the federal tax based on the users input. I am not entirely sure what it is doing, but it is definitely not what I want it to do. I commented out the loops because they seemed to have caused a problem, but there is still problems that are making the program do something else. Here is my code:
#include<iostream>
#include<string>
using namespace std;
double getData();
double taxAmount();
[Code] ....
Functions just seem like they are not my thing. It never gets to the second function to do the calculations and then return to main to display the results.
I tried changing the code to a switch(status) with a default: at the end that looped the "please try again" but for some reason, that was a fail, it created an endless loop.
View 15 Replies
View Related
Dec 24, 2014
My assignment is to pixelate an image based on users input. I have a structure that stores the image, and in this structure I'm storing the height and width and a dynamic array of RGBA struct.
This is my function. my main issue (that I've found) is offsetting and figuring out a way to handle the "edge" if the dimensions don't add up to the set pixelation size.
// @------------- Pixelation X
bool filter_pixelation(float percentageX, float percentageY, Picture& pic) {
// URL
/* 50% of 80 = (50/100) * 80 = 40 */
size_t perX = percentageX * (float)pic.width;
size_t perY = percentageY * (float)pic.height;
[Code] ....
Here is the getIndex function:
int getIndex(int x, int y, int width) {
return y * width + x;
}
View 1 Replies
View Related
Nov 5, 2014
Okay so I have to draw a square using "c" that draws according to the user input. Also, this has to be a function, and here is the code I have so far:
#include <stdio.h>
void DrawSquare(int length, char symbol);
void DrawSquare(int length, char symbol) {
int row;
int col;
[Code] .....
When I run this program it compiles fine but when the user input is recorded it just draws nothing but makes tons of spaces.
View 2 Replies
View Related
Oct 21, 2014
How can i repeat a loop based on the number inputted by the user?
View 4 Replies
View Related
Sep 27, 2013
how to stop outputting data based on a user input. The text file is as follows:
1. a
2. b
3. c
and the code I'm using is as follows:
int main (){
string line;
int search;
cout << "Enter a number from 1-3" << endl;
cin >> search;
search++;
ifstream myfile ("example.txt");
[Code]...
What I want to do is to just output number 1 (the whole line) if the user enters number 1. However, I get an error on the second condition w/c is the "&& line!= search"
View 1 Replies
View Related
Feb 7, 2014
I'm trying to create a function where it allows the user to type in multiple amounts of integers, so if the user wanted to have 3 different storages that hold different integers, the input would look something like this:
5
97 12 31 2 1 //let's say this is held in variable "a"
1 3 284 3 8 // "b"
2 3 482 3 4 // "c"
2 3 4 2 3 // "d"
99 0 2 3 42 // "e"
Since we don't know what number the user will input every time, I'm not sure how to create a dynamically allocated array that will create an x amount of arrays every time.. I want to be able to access each index of a, b, c, d, e or however many arrays there are.
So far, this is what I have, but I'm having trouble creating the arrays since it's unpredictable. I'm purposely not using vectors because I don't really get how pointers work so I'm trying to play around with it.
int* x;
int length, numbers;
cin >> length;
x = new int[length]
for (int i=0;i<length;i++)
{
cin >> numbers; //this doesn't work because it only grabs the first line for some reason
x[i] = numbers
}
View 3 Replies
View Related
May 24, 2014
I am trying to create a program that will calculate pi based on a user input for accuracy. If the user input .3 then when the leibniz infinite sum value at a particular i becomes less then the input of .3 then the loop will exit.
I have looked at a number of examples on the internet but I feel lost. I have put together working code that will infinitely output sums but I need the loop to stop when the sum value is less then the accuracy value.
My question is what is wrong with my while loop, why will it only give me infinite summations? How do I make it so that the loop will exit when my accuracy input is greater then the sum?
int main () {
double accuracy;
cout<<"Give an accurate number." << flush;//looks nice
cin>>accuracy;
int d;//initialize denominator
double pi = 0.0;
while(accuracy < d){
[Code]...
View 8 Replies
View Related
Feb 14, 2013
i can't seem to get my program to save the Set.savv file and encrypt it and decrypt it when user logs back on to there virtual file on a CD and writing it to the disk its self and closing the session
View 8 Replies
View Related
Nov 19, 2014
I have to read multiple text files and change all uppercase to lowercase. i also put in a little extra with finding values and spaces and punctuation. But nothing comes out so i don't know if the file is even being read or maybe I'm reading it but not accessing the right way.
string stdins;
char data;
//string line;
vector<char> a;
ifstream read;
read.open("ds.txt");
while( getline(cin,stdins) ) {
[Code] ....
View 2 Replies
View Related
Feb 13, 2014
how to carry out the conversions. The assignment is the normal hex to octal and Quart (base 4) via bit munipulation which I have worked out myself. However, I have been trying all day to figure out how to read in a string such as H1234, or O4567. How to parse the input I can handle the remainder myself. I'm just stuck and I've tried for hours.
View 5 Replies
View Related
Mar 11, 2012
Below given is the code, which allocates memory for a structure dynamically and stores value in its member. The problem is in the last scanf statement which reads 'ch'. The code will be in infinite loop as it doesnt executes the last scanf statement. The solution for this is (i use this) to add one more similar scanf statement for 'ch' in the very next line. If i do so, it executes the statement, reads 'ch' and then continues.
I want to know why it behaves like that..
struct student{
int usn;
};
int main(){
char ch;
struct student *s;
s=(struct student *)malloc(sizeof(struct student));
[Code] ....
View 11 Replies
View Related
Mar 10, 2014
i want to display all the contents of a file excluding one based on user input say i have 4 records in the file numbered 1 to 4....the user chooses 2 to exclude it outputs records 1,3,4,4 when it should be records 1,3,4 what am i doing wrong here is the code.its basically displaying the last record in the file twice
void excludeRecord()
{
ifstream read;
read.open("Data.txt");
int recordC =0;
string fnameC = " ";
string lnameC = " ";
[Code]...
View 2 Replies
View Related
Dec 15, 2014
I have to make a program that displays a square of asterisks based on the users input. Here is what I have so far.
#include<iostream>
using namespace std;
int main(){
int number;
cout << "Enter a number: ";
cin >> number;
for (int i = 0; i < number; i++){
[Code] ....
But the square needs to be hollow like this. So if the user enters 5 then the following square will be shown.
*****
* *
* *
* *
*****
How to make it do this.
View 11 Replies
View Related
Nov 23, 2012
I have an extra credit project where I'm supposed to calculate an approximate the user's age based on the current date and their birthday. My problem is that I am not getting the proper date and time. C++ keeps giving me some random date. I looked up c++ time format on the internet because this is extra credit and not in my book.
I am currently using dev C++ 4.9.9.2. Here is my current code :
// included libraries
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <time.h>
#define cls system("cls")
#define pauseOutput system("pause")
void printM(int x);
void age(int m, int d, int y, int &yearAge, int &monthAge, int &dayAge);
[Code] ....
View 1 Replies
View Related
Jun 12, 2014
I was trying to get the name of the user and print it but the only thing that i get is the first Character. For example, in this code, i try to get the name of the user and print it.
#include <iostream.h>
int main(){
char name;
cin >> char;
cout<< "welcome " << name;
return 0;
}
should i define "name" in another way?
View 3 Replies
View Related
Nov 1, 2013
So running the following code
Code:
#include <stdio.h>
int main(void) {
char c;
int i=1;
while (scanf("%c", &c)==1)
printf("loop sequence %i: %c(%i)
[Code] ......
Done it seems a "carriage return" serves two purposes here, one is to signal the program to read in the character typed in before the "carriage return", another serves as a second character typed, how can i do this cleanly, that is without having to use a "carriage return" as the second character to signal "I've typed in the first character already".
View 2 Replies
View Related
Sep 25, 2012
I am working to make a translating software from an Urdu sentence into Hindi and vice versa, i am using visual c++ 2010 software with c++ language. i have written an Urdu sentence in a text file. now i want to get a single character one by one from that file so that i can work on it to convert it into its equivalent Hindi character. when i use get() function to get a single character from input file and write this single character on output file, i get some unknown ugly looking character placed in output file. My code is as follows
Code:
#include<iostream>
#include<fstream>
#include<cwchar>
#include<cstdlib>
using namespace std;
void main() {
wchar_t arry[50];
[Code] .....
View 13 Replies
View Related