537 Posted Topics
Re: instead of using getline(), you should continue your use of the >> extraction operator. unlike getline(), the extraction operator depends on 'white space' delimiters. the way you are doing it now, you are trying to do is to store the entire first line into bevName :s | |
Re: what type of arrays are you using? are they int[], char[] string[]??? | |
Re: 1. you should #include<algorithm> 2. you create 'string line;' but then never assign anything to it.. 3. so when you call search(line.begin(), line.end(), search.begin(), search.end(), nocase_compare), arguments #1 and #2 will return iterators to a string of nothing. for more information: [url]http://www.cplusplus.com/reference/algorithm/search/[/url] | |
Re: When you say you need the "range of marks", are you asking for the the highest and lowest score for each exam? | |
Re: I believe your problems are here: [CODE] //line #78 if (currentPlayer ='X') //and line #81 else (currentPlayer = 'O');[/CODE] You are making a common mistake when it comes to boolean comparison.. take a minute, think about it, and tell us what ye' come up with. [I]In fact this error is … | |
Re: If ye' are trying to display an ascii escape character as text, simply add an extra \ backslash before each escape character. | |
Re: I suspect a '\n' newline character is being left in the input buffer when the user presses the ENTER key. Try using cin.ignore() right after line #24 to force the leftover newline character to be disregarded by your program. | |
Re: one thing that i notice is that you got a couple of smiley faces in your code. | |
Re: 1. you never initilize the 'count' variable.. it could be anything. (you should also do the same for 'average' as good practice) 2. you should decrement the count variable by 1 before using it in calculations in order to account for an extra loop iteration in the case of a … | |
Re: [quote]Just take my code above and edit to create what I asked.[/quote] would you like a side of fries with your order.. | |
Re: your search algorithm will probably look something like this: [CODE] bool found = false; int index = 0; cout << "Enter random zip code: "; cin >> zip_code; for(int i=0; i < max_number_of_cities; i++) { if(zip_code == mystruct[i].zip) { found = true; index = i; break; } } if(!found) { … | |
Re: you never #include<iostream> or #include<string> or using namespace std; you asked if line #3 is correct, it is correct; however, will continue to throw errors until you include the string library. | |
Re: just my two cents.. I'm not sure if you can derive your main() function from Deck.. (i've never done it this way) this would be new to me: int Deck::main() I would segregate your program into the standard three sections: .h header file, .cpp main driver, and .cpp function definitions … | |
Re: I believe this version of your program will at least compile: [CODE] #include<iostream> using namespace std; int A[5]; int ctr = 0; int main() { ctr = 5; while(ctr < 5); { cin >> A[ctr]; ctr++; } cout << A[5]; ctr = 5; do { cout << A[ctr]; ctr++; }while(ctr … | |
Re: [code] string stuff[10]; stuff[2] = "infinity"; for(int i=0; i<10; i++) { cout << stuff[i] << endl; }[/code] | |
Re: Although I don't fully understand the assignment, I will attempt to throw some code your way to help get the gears spinnin' inside ye' head. based on your current coding style, i would suggest simple if/else logic: [code] //all calls will be at least E1.50 full_cost = 1.5; //adjust call … | |
Re: For most assignments of this nature, most go with storing user input into a cstring.. then use a loop to display the contents of the string in reverse order. Simple. Straight-forward. | |
Re: [code] //Preprocessor Directives #include<iostream> #include<string> #include<cstdlib> #include<cctype> #include<ctime> using namespace std; //Function Prototypes void SeedRandom(); void PrintHeader(); void PlayOneMatch(int&, int&, int&, int&, int&); int GetPlayerChoice(); int DrawNum(int); void PrintMove(int, int, int&, int&); void WonAGame(char, int&, int&, int&); void PrintFinalResults(int, int, int, int); void Reset(int&, int&, int&, int&, int&, int&, int&); … | |
Re: one simple strategy, would be to pass the char array into your function as a reference.. therefore any manipulations you perform on the char array will affect it directly in memory. algorithmically, reversing the array is simple. create a new dynamic temporary char array of equal length. copy first element … | |
Re: you would either have to create a lookup table or use some other kind of construct (like switch/case)... there are no standard library functions to perform the string to number conversion. for large numbers, you would have to tokenize the string and create a number for each string individually. | |
Re: Here, you are attempting to assign a 'Nunu' object to another 'Nunu' object: [code] p[0] [B][COLOR="Red"]=[/COLOR][/B] a; [COLOR="Green"]//"Error 2 error C2582: 'operator =' function is unavailable"[/COLOR] [/code] Assignment among primitive data types, such as int, float, char, double, etc. is handled by the compiler with relative ease. But what happens … | |
Re: couple things: You are using cstring library functions, without explicitly including the <cstring> header. If it works, hey that's fine. Just letting you know. By putting your array counter at the beginning, you'll always skip over element[0]... I think this is why you are reading the same thing over and … | |
Re: the only time i can think of using friend functions is for operator overloading.. the rest of the time they should be avoided because they violate OOP data encapsulation. | |
Re: You need to refine your question before we go all out w/ a bunch of code to give you what may or may not be the correct answer. You unclear in some aspects of your question; for example, you state that you require an 'odd number' input from the user, … | |
Re: You may need something like this: [CODE] bool is_vowel(char& test) { switch(test) { case 'a': case 'e': case 'i': case 'o': case 'u': return true; default : return false; } } [/CODE] | |
Re: [quote]May I know use of Method returning a pointer in C++, please?[/quote] What you are saying resembles english and seems quite insightful, so I will offer you this: [CODE] #include<iostream> int* get_address(int&); int main() { int number = 0; std::cout << "Enter a number: "; std::cin >> number; std::cout << … | |
Re: [quote] This project will require you to develop three C functions: [/quote] You are asking for C help in a C++ forum. You deserved to be weeded out of the natural order of the human species. I should do your assignment in c++ and let you turn it in. | |
Re: [quote]but then new value that is to be inserted has to be after the current_index and the function i have now places it before i have no idea how to make that change [/quote] [CODE] data[current_index+1] = entry; [/CODE] | |
Re: Line #12: Initialize 'c' to 9 instead of 10. Line #32: Initilize 'g' to 9 instead of 10. | |
Re: [quote]"vector subscript out of range"[/quote] Just based on that piece of information alone, I bet you are attempting to access a vector element that is larger than vector.size() [CODE] vector<int> v; v.push_back(1); v.push_back(2); v.push_back(3); //No bueno... only elements 0,1, and 2 are currently populated: cout << v[3]; //Access out of … | |
Re: As stated by thomas_naveen, you have a classic eof() problem which will need to be remedied in order for your program to work. [quote] I can't understand why it says its out of range when the pos and length I supplied is valid.[/quote] The position of your first white space … | |
Re: If the network printer is selected as the default device, why not just print normally? Printing (as far as I know using win32 api, which I know you don't want to use) involves the evokation of a standard dialogue box in which the use gets to choose the printing device … | |
Re: Here is a freebee for ye': [quote] c) create a date constructor that reads the system date using the standard library functions of the <ctime> header and sets the Date members[/quote] [CODE] class Date { public: //Default constructor Date(); private: //Date members struct tm* timeinfo; time_t rawtime; int day; int … | |
Re: In your example: (5 + 6(3+2) - 2(8*2) +1) Moving from left-to-right, in order to find a valid parenthesized pair, you have to find any condition where a ')' is found after traversing the most recent '(' From left-to-right, anytime multiple '(' are detected, the previous '(' position should be … | |
Re: [quote]Your program should prompt the user to enter the number of rows and columns in the 2-d grid.[/quote] since you will have the user define the dimensions of your 2d array, you should use a dynamic 2d array: [CODE] int rows = 0; int cols = 0; cout << "Enter … | |
Re: At first glance, your stuff looks good... Have you tried #include<iostream> ?? | |
| |
Re: [LIST] [*]create 2 objects of type 'ifstream' [*]open the two files [*]read in the desired stuff to a container of your choice (usually string objects or vectors) [*]compare the two strings [/LIST] [CODE] string word1, word2; ifstream infile1, infile2; infile1.open("doc1.txt"); infile2.open("doc2.txt"); word1 << infile1; word2 << infile2; if(word1 == word2) … | |
Re: Although I'm not familiar with Allegro, I am almost certain your game uses a single bitblt() (or "blit()" in Allegro I think) to constantly update the screen.. you'll need to learn how to "double buffer" your screen in order to gain that fluid 'non-flickering' update that ye' desire. Although [URL="http://www.winprog.org/tutorial/animation.html"]this[/URL] … | |
Re: [CODE] #include iostream using namespace std; int funcReturn(int& index); int main() { for(int i=0; i<3; i++) { cout << funcReturn(i); } return 0; } int funReturn(int& index) { int a[3] = {33, 44, 55}; return a[index]; }[/CODE] | |
Re: [url]http://www.cplusplus.com/reference/string/string/find_first_of/[/url] [CODE] bool is_single_vowel(string word) { //All words contain at least 1 vowel; find it: size_t found = word.find_first_of("aeiouAEIOU"); //Handle Special Case: If no vowel was detected, word must be using single 'y' as a vowel: if(found == string::npos) return true; //Attempt to find any occurance of a second vowel … | |
Re: try this: [CODE] string filename; cin >> filename; filename += ".dat"; outFile.open(filename.c_str()); [/CODE] | |
Re: Here is an in-depth discussion I googled concerning the dangers of using sizeof(array)/sizeof(arraytype) in order to get current length of an array: [url]http://www.gamedev.net/community/forums/topic.asp?topic_id=345898[/url] [U]Some alternatives to consider[/U]: [LIST] [*]Dedicate a 'size' variable to hold number of entries made into an array. [*]Use null-terminated c-strings; get array length using strlen(). [*]Use … | |
Re: Winsock is very popular, easy to use, and is a very good skill to have on the ol' resume. Companies will love you. | |
Re: [quote]The problems I'm having now are that the user is only allowed to input a number of sticks to remove once[/quote] I believe this problem may be due to an incorrect (and easily fixable) test condition in line #32. [quote] Also, the computer is not generating a number 1 through … | |
Re: It seems to me that making a function call to determine who the current player is in a game of tic-tac-toe is overkill. It is safe to assume that there will always be two players. It is also safe to assume that if player 1 went, then it will be … | |
Re: Your 'function-local' variable named TotalMPG we be created and thusly destroyed with every call of the MPG() function. Try creating a class variable that will retain the odometer reading. | |
Re: [U]Useful tips[/U]: you can consolidate lines 13 through 33, and eliminate lines 35 through 44 by doing this: [CODE] // Initializing the eight choices. int iChoice1 = (rand() % 8) + 1; int iChoice2 = (rand() % 8) + 1; int iChoice3 = (rand() % 8) + 1; int iChoice4 … |
The End.