456 Posted Topics
Re: And then ... perhaps next step ... 'revise code to crash proof input' ... i.e. to accept only valid user input: # takeInHousePrices.py # def takeInInt( msg, low, high ): while 1: try: val = int( input( msg ) ) if val == 0 or low*1000 <= val <= high*1000: … | |
Re: > We can create an array of objects for any class , irrespective of *whether it has a default constructor or not* Is the above really true? Please see ... http://en.wikipedia.org/wiki/Default_constructor and note the following example that needs to have a defined default ctor /* If some constructors are defined, … | |
Re: You could make a copy of the series of numbers, then sort the copies, and then compare the sorted series to see if the same. | |
Re: Why not use C++ string since you are using C++ ... and something like below ... ifstream fin( fnameCppStr.c_str() ); if( fin ) { int numWords = 0, numChars = 0; string word; // input each word until end of file ... // while( fin >> word ) { ++numWords; … | |
Re: * Do you know how to read a (.txt) file in C? * You could use an extra large array of C strings (Or use dynamic memory ... and a dynamic array, a Cvec) ( see: http://developers-heaven.net/forum/index.php/topic,2580.0.html ) | |
Re: Do you have examples of output for input of 1 and 2? (Or is the first valid input 3?) | |
Re: > any suggestions on how to replace the specific character with a different character within the string while running a loop? I am in a no prereq class and am not really connecting with this... Hint was: > loop, test character code, if one that needs replacing replace it... Further … | |
Re: You might also like to see this Python 3... example: (that uses a function to loop until valid integer input) (and that loops to ask user if more numbers to be input) (and that demo's the use of a list 'generator') (and that demo's the use of 'join') # sumNumbers.py … | |
Re: 100+100 -100-100 -(100)+(-100) sqrt(100) The last line above could be tested / handled by: if "sqrt(" then if int then if ")" then process ... The next to last line could be tested / handled by: else if "+(" or "-(" then if int then if ")" then if valid_binary_op … | |
Re: > The computer will select a secret number with five different (unique) digits. The object of the game is to guess that secret number. Each guess is answered by the number of digits in the guess number that match or occur in the secret number. You will also be told … | |
Re: You could loop until all input was exhasted putting each next element into the next spot in the array on each loop and yes ... you can also dynamically allocate memory for your array ... and expand the array if it needs more memory You might like to see an … | |
Re: This may get you started ... // function to return true if char c // passed in is a vowel ... // otherwise to return false bool isVowel( char c ) { c = toupper(c); if( c == A' || c == 'E' || c == 'I' || c =='O' … | |
Re: @Avishek_1 NOT good to use gets ... NOR to revert to old style C++ and mix up OP using stdio.h when OP was using C++ <iostream> Also since OP using C++, best to use C++ string. So ... would recommend something like this instead: #include <iostream> #include <sstream> // re. … | |
Re: Recursion can be tricky ... especially when you first try it ... so look up lots of examples where recursion is used. For a popular example, see 'quick sort' The following (inefficent design) on a related example may give you some ideas on how to get started ... /* getLastCharRecursive.c … | |
Re: One big thing that is very practical: Collecting and Analyzing Data Note that 'Process Control' depends on the above. | |
Re: Since you are using C++, you can use an array of C++ string to hold your words. This may help get you started ... const int MAX_NUM_WORDS = 1000; // make big enough // ... // int main() string words[MAX_NUM_WORDS]; istream fin( "nameOfYourFileOfWords.txt" ); int n = 0; if( fin … | |
Re: Why are you using ... "ArrayStack.h" It would seem much better to use the C++ STL stack (or list) to hold each char ... then we can 'talk' ... Also ... a test program ... and your results with your input vs what you expect to get. | |
Re: Show us the code you have so far ... are where you think you are stuck. Here is a student beginner level example of using functions to validate user input ... // getValidInt.cpp // http://developers-heaven.net/forum/index.php/topic,46.0.html #include <iostream> using namespace std; int getValidInt( const char prompt[] ) { for( ; ; … | |
Re: 'const' ... in your examples ... tells the compiler that the values in the array are NOT to be changed ... and the compiler will warn you then, if you / your program ... later ... tries to change any values in the array ... Try compiling some code, that … | |
Re: @naveen1993 Please note: 1. old post (now dead? - maybe you missed the date?) 2. NOT portable code ... if one uses <conio.h> , clrscr, getch, etc... 3. maybe you missed the CLEAR warning of @Ancient Dragon about NOT using gets!!! Please Google ... "C why DO NOT use gets" … | |
Re: Since using C++, why not use C++ string and gain the ease of its use ? Try something like this: #include <iostream> #include <string> using namespace std; void my_swap( char& a, char& b ) { char tmp = a; a = b; b = tmp; } // passed in string … | |
Re: In case you have not yet encountered using the C++ STL vector container, (which is really just an easily re-usable and easily expandable dynamic array), you might like to see this demo ... that just uses an array with the max size pre-fixed at compile time ... Note the little … | |
Re: @naveen1993 please see my comments after your post at: http://www.daniweb.com/software-development/c/threads/469587/problem-in-accepting-string-via-gets-function-in-c | |
Re: You may like to try this C 'readLine' emulation of C++ 'getline' ... /* CppToC_via_readLine.h.c */ /* using readLine to emulate C++ getline ... */ #include "readLine.h" /* get copy of file: "readLine.h" at this next link ... */ /* http://developers-heaven.net/forum/index.php/topic,2580.msg2864.html#msg2864 */ char encode( char plaintext ) { if( isupper(plaintext) … | |
Re: If you write a small program to loop through all the char's a..z and A..Z and take the difference of each matching pair ... the results may give you a 'heads up' on what you may be seeking ? for( int c = 'a', c2 = 'A'; c <= 'z'; … | |
Re: Some times the very beginning steps of computer programming seem 'very hard' ... but like learning any new complex thing ... once you 'see' how it works ... and 'how to make it work' ... you are well on your way :) The tricky part (at first with using scanf … | |
Re: Your questions are not really clear ... If you need different sized arrays ... you could use dynamic allocation of memory or just use two defines #define SIZE_10 10 #define SIZE_20 20 // etc re. the 2nd question ... you can use if( condition1IsTrue ) { /* */; ) else … | |
Re: What do you already know about a 4th power poly... ? Can you (differentiate and) find the max (extreme points -> if the graph of y = ax^4 + bx^3 + cx^2 +dx + e opens down) ... or min ... if it opens up ? From the extreme points … | |
Re: Recalling the above good insights of @Ancient Dragon ... > I would do it by using an array of 255 ints, each element in the array represents one of the characters in standard ascii character set. So, if you enter 'A', then all you have to do is increment array['A']++. … | |
| |
Re: Just looked your problem over ... This may get you started ... //5 courses available //only 8 allowed in each course //(so ... in main ... need 5 queue, each of size 8) // perhaps an array of StudAryQue // StudAryQue mySchool[5]; // holds all ... // or ... // … | |
![]() | Re: You have several compile errors ... In line 81: > ISO C++ forbids variable length array 'boardWithPieces' You could use a ... vector < string > vecStr( size ); // calls constructor // if you really need an 'array of strings' You also have redundant and several C (not C++ … ![]() |
Re: Ok ... post the code you have so far ... and where you think you are having a problem. | |
| |
Re: Python lends itself to jumping right in and start coding... This example code below may give you some ideas about how to get started ... # selectRobot.py # # 2014-03-26 # ''' The output will be like below: what type of robot application you like choose? a) assembly b) spot … | |
Re: Or ... start bottom up ... and code in small steps ... making sure that it 'works' as expected, (gives exact desired output), at each step ... and that YOU UNDERSTAND EACH step! There is no shortage of example code ... re. matrix multiplication ... on the web ... if … | |
Re: You could try something like this ... (that uses the code given you by @Gribouillis ... slightly revised ... and with comments added that may help explain it for you.) filename = 'myData.txt' ''' 07 13 14 23 45 - 04 13 27 34 41 47 - 49 22 24 … | |
Re: > Because maybe he need to show example of goto statement, I don't care about reasons. Problem is solved and that's all I care about. @Kristian_2 You do know that there is much more to coding, than ... > Problem is solved and that's all I care about. Program (logic) … | |
Re: Show the code you have so far ... and where you think you get stuck. | |
Re: Show the code you have ... and where you think you are stuck ... | |
Re: You may like to look here ... [insert sort linked list](http://developers-heaven.net/forum/index.php/topic,310.0.html) | |
Re: Sometimes ... the obvious ... is alarmingly simple ... when you 'see' it :) C arrays start at index 0, so next in, from front, has index 1, and ... the last index is size-1 (if size > 0 ), so next to last index is size-2 (if size > … | |
Re: > hint_prompt = hint_prompt.lower() the string is converted to all lower case | |
Re: Show the code you have ... and where you think you are stuck ... | |
Re: Hey ... start a new thread please ... did you not see that one was 5 years OLD ? int main() // not void main in standard C { // your code ... return 0; // main returns an int in standard C } | |
Re: You need to show the code you have so far ... and where you are stuck. | |
Re: You need to show the code you have so far ... and let us know where you are stuck. | |
Re: Since you are using C++, why not use C++ string (not C string) And don't use (risky) gets ... (even in C) In C++ with C++ string `#include <string>` then can code string cppStr; cin >> cppStr'; // or ... getline( cin, cppStr ); Also ! it is ... int … | |
Re: Perhaps your design spec's... really does want you to copy each user input to a file (append to a file) ... right away after each line has been input? The example 'dialog', you provided, does 'lend itself' to that simple interpretation ... yes/no ? If that is what was 'expected', … | |
Re: @pyTony: Can one still use raw_input in Python 3 ? |
The End.