5,676 Posted Topics
Re: OK, you need to think about what you need. [ICODE]getchar()[/ICODE] inputs a single character. [ICODE]putchar()[/ICODE] outputs a single character. When you input a character, 1) if it's a letter, output it. 2) if it's not a letter, 2a) if it's the [I]first[/I] non-letter, output a \n 2b) if it's [I]not[/I] … | |
Re: [QUOTE=Ancient Dragon;]First, its not good to open the same file twice. Use just one FILE* pointer and use it for both reading and writing. Call fseek() to move the FILE pointer back to the beginning if you need to but its not necessary to open the file again.[/quote] I disagree. … | |
Re: Usually command line arguments are meant to pass data into the program, such as - a file name - switches that modify execution in some way - specifying the exact data to be worked on Config files 'define' the environment for the program. Such as changing the program's default values … | |
Re: Read a character at a time. If it's a letter, add it to the matrix. If it's a \n, move to the next row in the matrix. Read the words into an array. | |
Re: To debug your code, add output statements in key places to show you what key values are at each step of the program. If one of the values displayed is wrong, you now look at the code to find out why. Of course, you need to know what the values … | |
Re: Since you are "[I]leraning c++ at the moment[/I]", I assume it's from a class. If so and you've never heard of vectors, don't bother with them. Your instructor will get there eventually. Your best bet is the array idea. | |
Re: [QUOTE=cdudefire;][CODE] if (sumd==4 || sumd==5 || sumd==6 || sumd==8 || sumd==9 || sumd==10) { d1 = rand()%6+1; d2 = rand()%6+1; sumd = d1 + d2; if (sumd==7) { printf("You rolled a 7, you lose.\n"); lostp++; } if (sumd==4 || sumd==5 || sumd==6 || sumd==8 || sumd==9 || sumd==10) { printf("You … | |
Re: What does your program print before and after it goes wrong? | |
Re: Water? Never!!! Mountain Dew -- the drink of techies. | |
Re: Look at each character. When you see an H remember it. If the next letter is E, remember it, else forget everything. Continue until you have all the letters. Now check if there is a letter before or after these letters. If so, ignore it all, otherwise, change the characters | |
Re: [QUOTE=cse.avinash;]addition of digits of number if divisible by 3 then that number is divisible by 3. 396=3+9+6=18=1+8=9. 1)store 3,6,9 using enum. 2)sum=0 3)input a string a. 4)convert each char into digit using atoi. 5)add that char to sum and store it in sum. 6)assign sum to a. repeat this process … | |
Re: Personal opinion -- If a program blinks at me it's going to be the last time I use it. I would look for a less obnoxious program... | |
Re: What did SEARCH at the top of the page tell you when you tried to find your answer? | |
Re: You have to create the "file1.dat" filename each time through your loop. You need [iCODE]stringstream[/iCODE] or [iCODE]sprintf[/iCODE] or something similar to do that. | |
Re: [QUOTE=dimmu11;]line 35 of the first block of code.. as i said earlier, the second if statement of my populate random function. please read what I said in the original post first.[/QUOTE] I read it... You said [QUOTE=dimmu11;]I tried debugging it, and found that there is [B]something[/B] wrong in the second … | |
Re: Please [url=http://www.gidnetwork.com/b-38.html]format your code[/url] at all time so we can read it. This has been mentioned before. | |
Re: [QUOTE=anuragcoder;]BGI Graphics are not supported under windows...[/QUOTE] Since when? Last time I compiled code I wrote 20 years ago, it compiled and worked. And this was within the last year. Even though BGI and Turbo are old, if you have something to complain about it would be much more helpful … | |
Re: [QUOTE=meli123;]I would like to make a program which allows you to enter a number (say 145). It reads the [B]3 CHAR[/B] and prints the largest one. [/QUOTE] [QUOTE=meli123;]I have used for loops but not arrays!! So it would be great if I could do it in Arrays..[/QUOTE] Input the number … | |
Re: [QUOTE=ashok1514;]the parameters taking of printf function is from right to left..... So in the given problem the function executes as follows.... b=1; printf("\n %d %d %d",b=15, b>9, b<9); So first it executes the condition b<9 but here b=1 next it executes the condition b>9. Here also b=1 and the last … | |
Re: Let's put this in perspective. I will rewrite your question and see if you think your request is appropriate. [QUOTE]Hello, I am new to being a doctor (3rd year student) and I would like to perform my first surgery something similar to open heart surgery obstacle is how to find … | |
Re: Use [B]cin.get()[/B] or [B]cin.getline()[/B]. Both are C++ input, rather than non-standard C input. And get rid each and every [B]goto[/B] statement. They are not needed if you program your [B]case[/B] statements correctly and add appropriate loops your program. | |
Re: [iCODE]*(mpg+ctr)[/iCODE] is basically the same as [iCODE]mpg[ctr][/iCODE] Tearing it apart: [B]mpg[/B] points to the array. [b]mpg+ctr[/b] points to the [I]ctr[/I]th element in the array. [b]*(mpg+ctr)[/b] therefore is the value at the [I]ctr[/I]th element | |
Re: [QUOTE=Fbody;]Are you required to use arrays, or can you use vectors? Using a std::vector will make your life much easier because a vector is easy to change and re-size (dynamic) whereas arrays are not readily adjustable (static).[/QUOTE] If he doesn't know classes it's a sure bet vectors are out of … | |
Re: [QUOTE=ausgurl;]Hi Everyone :) I know you don't like homework help..but I have tried to answer it and got a resit and now I have no idea!! [/quote] Considering over 94% of all threads are asking for homework help, I don't understand how you got this idea. As long as you … | |
Re: [QUOTE=Taywin;1646544]What I don't understand is that why the book gives an example which does not really show the efficiency of the switch-statement. This example could easily be done and easier to understand using if-else statement...[/QUOTE] Because when you are learning, the easiest example is the easiest to understand. Doh! | |
Re: When you write to 'buffered' device, sometimes the system will hold the characters in the buffer until a specific thing happens: 1) the buffer is filled 2) a NEWLINE \n is added 3) an explicit command (flush) is used It all depends on how the compiler I/O is designed. So … | |
Re: [QUOTE=jlharri9;][CODE] case 1: fdeposit = depositBalance (deposit); cout << "After your deposit your current balance is $" << fdeposit << endl; continue; case 2: fwithdraw = withdrawalBalance (withdrawal); cout << "After your withdrawal your current balance is $" << fwithdraw << endl; continue; case 3: cout << "Your balance is … | |
Re: You are doing it the hard way. First, make the dimensions of [B]grid[/B] large. This way you can have different size maps if you want them. Read a line into the first row of [B]grid[0][/B] Read the next line into [B]grid[1][/B] etc. Count the number of lines as you read … | |
Re: It's the web link to the post itself. You could have just clicked it... | |
Re: Yes, start over. 260 lines is way too many for this program. 1) Get rid of ALL the [iCODE]system("cls")[/iCODE] calls -- they are annoying to the user at best. 2) NEVER use a [iCODE]goto[/iCODE] statement. They are not needed in 99.99% of C/C++ programs. 3) In each switch statement for … | |
Re: You can use IF statements, SWITCH statements, ARRAYs, and FUNCTIONS to make your code more compact. You don't need 37 IF statements to test the number field... | |
Re: I'd do something a little more 'noobie' (starting from [B]Narue[/B]'s code): [CODE] #include <cstdlib> #include <ctime> #include <iostream> using namespace std; int main() { int n; int val; int array[MaxSize]; bool done; for (n=0; n<MaxSize; n++) array[n] = 0; srand((unsigned)time(nullptr)); cout << "Enter N: "; if (cin >> n) { … | |
Re: [QUOTE=efigen;1644475]I have an input file that i make into a string, it looks like this "1+2+3+45*5*2" My problem is when i print the string it always prints as single characters instead of 45 i get 4 5, how do i fix this. heres a small piece of the code. [CODE] … | |
Re: [QUOTE=Duoas;]Hmm, without knowing anything at all about the OP's original purpose, this thread has become a hate-war over clearing the screen.[/QUOTE] Yes, and it was thankfully dead for 6 years until a [B]wasted[/B] person resurrected it with a worthless suggestion. | |
Re: And I'm still waiting for you to [QUOTE=WaltP;]1) Place comments on each line of your code that explains why that line is there. "[I]Because someone said so[/I]" is not acceptable. 2) Write down the steps needed [B]in detail[/B] to check the beginning of the file for your bad file indicators … | |
Re: [QUOTE=Jared1337;1643649]I'm having trouble getting this program to work for roman numeral conversion. I hope it says that i have one error, which is C2110: cannot add two pointers. here's what i have so far... ANY help would be great[/QUOTE] 1) Use CODE Tags 2) Don't tell us you [I]hope[/I] for … | |
Re: [CODE] int num; int die; cout << "What number do you think you'll roll? " << endl; cin >> num; die=(int)(rand()%6)+1; // So far, so good if (num<6 && num>0) { // So 0 is a proper guess? But 6 is not? srand((unsigned)time(0)); // Why are you seeding the random … | |
Re: [CODE] Sub btnModify_Click() delete *.* End Sub [/CODE] | |
Re: The Algorithm: Given the first two terms are 0 then 1, each successive term is the sum of the previous two terms. | |
Re: [QUOTE=sundip;][code] char firstChar[256]; size_t chars_read= 0; int currentLocation = 0; while (input.good()) { nextChar = (char) input.get(); firstChar[chars_read++]=(char)input.get(); } [/code][/QUOTE] So now in the [ICODE]firstChar[][/ICODE] array you have every other (even numbered) characters from the file. 1st, 3rd, 5th ... characters are not in the array. And this is supposed … | |
Re: [QUOTE=MeOnly;]4. How does it happen that people here misunderstand each other frequently? [QUOTE=debasisdas;]We do it frequently for some serious fun and to confuse others. [QUOTE=MeOnly;]Now I'm confused :confused:[/QUOTE] [QUOTE=Pro2000;]Me too :D[/QUOTE] [/QUOTE] [/QUOTE] See? It works! [QUOTE=Nick Evan;]You're not going to turn in yet another internetstalker, right? ("ohmygod, it's a … | |
Re: change [iCODE]printf()[/iCODE] to [iCODE]fprintf()[/iCODE] | |
Re: Start by adding print statements to be sure you are reading the input properly. Program one step at a time. First input. Make sure it works. Next internal representation of the values -- print them. Make sure they are correct. Next... | |
Re: Do you know what the term [B]append[/B] means? [iCODE]fp=fopen("c:\\folder/file.txt","a+");[/iCODE] | |
Re: [QUOTE=Ancient Dragon;]Oh really??? Where are they then? The only links to code snippets any more are from within the member's profile. But I don't want to search 50,000+ member's profiles just to find tutorials and/or code snippets.[/QUOTE] 908,364 Members profiles :icon_wink: | |
Re: Forget the vector. Just 1) Create a string [B]array[/B] with all the names in it. 2) Use [iCODE]srand()[/iCODE] [B]once[/B] to initialize the random function. 3) call [iCODE]rand()[/iCODE] to get your random number [B]x[/B] from 0 to 3 4) Display the [B]x[/B]th name from the array. | |
Re: Create a data file where each line defines the values for each monster. Then create a read function that reads the file. This way you can add and modify monsters any time you want and won't have to change the program. | |
Re: [QUOTE=Desh2350;]I need a simple error check, so that if the user enters the wrong type of character, he/she will be notified and allowed to re-enter a new value. [/quote] Rad the input as a string. Then test each character to make sure it's a valid number. [QUOTE=Desh2350;]Secondly, I need some … | |
Re: [QUOTE=micheal Amirul;1641712]this is not my homework..but its just my exercise..i have done to built this..but it cant run properly..[/QUOTE] Why not? We know less about your program than you do. [QUOTE=micheal Amirul;1641713]can somebody help me and explain what the question want..i dont understand the question..[/QUOTE] Seems obvious to me. What … | |
Re: [iCODE]extern[/iCODE] the variables in question. Look it up... |
The End.