C++ :: Wap To Read A Character From User And Test Whether It Is A Vowel Or Constant
Jan 10, 2014How to do this?
View 10 RepliesHow to do this?
View 10 RepliesI'm trying to test if a character is a vowel. I made a separate function for the test, I'm not really sure how to get my return value to output whenever I call the function from main?
Also, I'm not good with while loops and can't figure out how to get it to continue asking whether or not the user wants to keep entering values.
#include <cstdlib>
#include <iostream>
using namespace std;
bool isVowel(bool);
int main(int argc, char *argv[]) {
char var1, cont;
[Code] ....
Can distinguish between character constant and string constant giving examples
View 1 Replies View RelatedI keep getting this warning message and I do not know how to fix it. Is it because I'm using char to instead of strings to replace all 't' with 'lp'?
#include<iostream>
#include<string>
#include <stdio.h>
using namespace std;
char * scanf(char * a) {
[code]....
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] ....
The program is supposed to read in a string from the user and then output the number of each vowel that the string has. My first function is initializing the vectors, and the one that I'm having trouble with is the function used to read the string from the user and save it.
Here's my code:
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
// FUNCTION PROTOTYPES GO HERE:
void init_vectors(vector<char> & vowels, vector<int> & frequencies);
string read_text(const string & prompt);
[Code] ....
And I'm getting the error:
freq.cpp: In function ‘std::string read_text(const std::string&)’:
freq.cpp:74: error: no matching function for call to ‘getline(std::istream&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’
I'm not too sure if I can't use the function getline here or if there is something wrong with the function prototype itself but I'm pretty sure there isn't an error there as it was given to me.
Here's the line of code with the warning
Code: if((addressbook[3][num][4]=='-')&&(strlen(addressbook[3][num])=='10'))
Or what might be the possible causes of such a warning?
Here's my code. The error's at the last line.
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define max_con 30
void add_contact();
void edit_contact();
void del_contact();
void list_contact();
[Code] .....
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.
How do I write an a program that will read an input file character by character?
View 1 Replies View RelatedIn 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.
I'm creating a program that takes user input in the form of a string and tests to see if it matches a word. Each correct word will increase their score by one. Here is a portion of the code that is not working.
...
else if(s == 32) {
if(!currentLetter.empty()) {
currentLetter.erase(currentLetter.length() - 2, currentLetter.length() - 1);
} if(currentLetter.compare(oWord) == 0) {
[Code] .....
To me, this looks like it should do a very simple task as intended-take a String, compare it to another, and reset the word if they match or output incorrect if not. But, I'm not sure if there is some quirk in C++ with Strings, because this code always outputs Incorrect. Please try again. and the score never increases. I also tested this by literally setting the strings equal in the code, which still resulted in it not doing what it's supposed to.
I want to create a game that will test the attention and mind flexibility of the user. So the challenge is The user will be given 50 rounds, and each round should generate a random combination of text and words.Then the user must Press 'Y' if the UPPER CASE text spells out a color that match the BACKGROUND. But if the text are in LOWERCASE the user must press 'N'.(Note: you can change the keys to any key from the keyboard if you wish to)
Then I also want my program to record the high score each time the program prompts the user if he/she wishes to play again.
I also want to control the combinations by NOT allowing the text color and background color to be the same.
I also want the combination to generate an AVERAGE of 50% correct combination and 50% wrong combinations. The I want to use is only Red, Blue and Green
HIGH SCORE Determinants:
1. Accuracy ( (Number of corrects / 50 ) * 100% ) - The higher the better.
2. Time in seconds (Time Ended - Time Started) - the lower the better.
Computation for high score: 10 000 * ( (Accuracy) - (2 x total Attempts - Time) )
What I need to do Is constantly read the cpu percentage and display it to a textbox, but the issue is I am using the windows form not the console so I cant use a while loop. I think my best bet is to use an event, but I am not sure how.
View 6 Replies View RelatedAt the moment I am making program that will use a 2d selection of "cells" to make a "map" of sorts. However, the size will not be known until run time.
I figured using an array would good, because once the size is chosen it won't be changed. However I can't create an array without using a constant.
So the first question is, can I create a constant at run-time with a user entered value that can then be used for an array size? If so, how?
Otherwise, what are my options to achieve this? I know vectors can be used, but A, my compiler keeps giving me problems even when C&P some code bits (yes I even remembered to #include and such) and B, I noticed that vectors reserve extra memory for when the size changes but this is bad (well my dinky little program won't notice, but trying to set good habits as I learn, so I'm keeping it in mind) as I don't need and don't want to allow the size to change after creation.
Which leads to number three, if I do have to use vectors, how can I prevent any accidental size changes after the initial size is determined?
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 RelatedBelow 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] ....
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?
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".
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] .....
I'm very new to c programming and I have some background in C# and java. I am supposed to read a string from input then determine in that string, which character is the largest, i.e. I think b>e and e>z, e.t.c. If the string is empty I should return '