5,676 Posted Topics

Member Avatar for Benifited

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] …

Member Avatar for Lordvivi
0
211
Member Avatar for deepmala8

[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. …

Member Avatar for Ancient Dragon
0
917
Member Avatar for dospy

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 …

Member Avatar for dospy
0
2K
Member Avatar for FinaL111

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.

Member Avatar for FinaL111
0
280
Member Avatar for tayler

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 …

Member Avatar for hszforu
0
166
Member Avatar for Xide

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.

Member Avatar for mrnutty
0
167
Member Avatar for cdudefire

[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 …

Member Avatar for cdudefire
0
2K
Member Avatar for geeksforgeek
Member Avatar for Narue
0
104
Member Avatar for MooGeek
Member Avatar for Netcode
2
156
Member Avatar for Rmaure

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

Member Avatar for dospy
0
222
Member Avatar for sydsine

[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 …

Member Avatar for cse.avinash
0
453
Member Avatar for iAMyours

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...

Member Avatar for WaltP
0
91
Member Avatar for meshael

What did SEARCH at the top of the page tell you when you tried to find your answer?

Member Avatar for WaltP
0
97
Member Avatar for thenewbiecoder

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.

Member Avatar for WaltP
0
258
Member Avatar for dimmu11

[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 …

Member Avatar for WaltP
0
133
Member Avatar for somshridhar

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.

Member Avatar for somshridhar
0
321
Member Avatar for niyasc

[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 …

Member Avatar for ziyadgodil
-4
10K
Member Avatar for meli123

[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 …

Member Avatar for TrustyTony
0
297
Member Avatar for hackit

[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 …

Member Avatar for Narue
0
154
Member Avatar for whiteLT

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 …

Member Avatar for whiteLT
0
89
Member Avatar for zendet

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.

Member Avatar for WaltP
0
4K
Member Avatar for king03

[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

Member Avatar for Ancient Dragon
0
138
Member Avatar for rjcenteno

[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 …

Member Avatar for rjcenteno
0
187
Member Avatar for ausgurl

[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 …

Member Avatar for Reverend Jim
0
152
Member Avatar for Nastadon

[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!

Member Avatar for Taywin
0
205
Member Avatar for urbangeek

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 …

Member Avatar for Narue
0
2K
Member Avatar for jlharri9

[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 …

Member Avatar for raptr_dflo
0
197
Member Avatar for Chuckleluck

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 …

Member Avatar for Chuckleluck
0
607
Member Avatar for Reverend Jim
Member Avatar for SquigsSquigley

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 …

Member Avatar for raptr_dflo
0
1K
Member Avatar for Um num num

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...

Member Avatar for ProgrammingGeek
0
158
Member Avatar for PaulProgramer

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) { …

Member Avatar for PaulProgramer
0
222
Member Avatar for efigen

[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] …

Member Avatar for WaltP
0
101
Member Avatar for saurabh_s

[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.

Member Avatar for Duoas
0
541
Member Avatar for guccimane

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 …

Member Avatar for WaltP
0
103
Member Avatar for Jared1337

[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 …

Member Avatar for raptr_dflo
0
4K
Member Avatar for aspirewire

[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 …

Member Avatar for WaltP
0
129
Member Avatar for Djscorpion011
Member Avatar for MooGeek

The Algorithm: Given the first two terms are 0 then 1, each successive term is the sum of the previous two terms.

Member Avatar for reactivated
0
383
Member Avatar for guccimane

[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 …

Member Avatar for vijayan121
0
281
Member Avatar for Hani1991

[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 …

Member Avatar for MooGeek
3
403
Member Avatar for aero31aero
Member Avatar for khsoccer

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...

Member Avatar for Schol-R-LEA
0
443
Member Avatar for veeresh_cm

Do you know what the term [B]append[/B] means? [iCODE]fp=fopen("c:\\folder/file.txt","a+");[/iCODE]

Member Avatar for TrustyTony
0
314
Member Avatar for jingda

[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:

Member Avatar for ggeoff
0
555
Member Avatar for NetJunkie

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.

Member Avatar for mrnutty
0
200
Member Avatar for valestrom

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.

Member Avatar for mike_2000_17
0
242
Member Avatar for Desh2350

[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 …

Member Avatar for Ketsuekiame
0
252
Member Avatar for micheal Amirul

[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 …

Member Avatar for WaltP
0
169
Member Avatar for valestrom

The End.