Well perhaps in the future magic will replace technology ;)
You've got it backwards. The future technology is the current magic. Corollary to Arthur C Clark's law.
Well perhaps in the future magic will replace technology ;)
You've got it backwards. The future technology is the current magic. Corollary to Arthur C Clark's law.
And again. No Code Tags. Non standard code. Attempting to do other's homework for them. Yet another bad post.
I don't like the function at all. It would be better IMO to read the file a character at a time and watch for the \n rather than reading an entire buffer, finding the \n and seeking back to reset the file pointer. Much less work.
1) Never call srand()
where you need a random number. Call it once at the beginning of the program only.
2) use a while
loop instead of a recursive function.
No, don't try that. It's worthless.
No, you're not having trouble. You're not even trying to check if a negative number has been entered. You need to make an attempt. Where is the most logical place to test for this negative number?
extern
s are used to "pass" variables from one source file to another. Not within a single source file. Remove the extern
to make the variable a global and it should work fine (with one more change I leave to you.)
Why are you trying to do this using wide strings? Based on your first post it was an arbitrary decision.
Please repair my loop.
No, you repair it? What seems to be wrong? It's upside down, right? So reverse the code properly inside the outer loop.
Try writing this a piece at a time.
1) Create the pattern
*
**
***
2) Put that in a loop to make
*
*
**
*
**
***
3) Make the pattern
&
&&
&&&
4) Add a loop to make
$
$$
$$
$$$
$$$
$$$
5) Merge all the pieces to create the final pattern. You might have to plan the pattern and code with pencil and paper to get the pattern correct. Don't just try to create it while sitting at the computer. Good programmers to a lot of non-computer work first to plan out the code.
So what is the program doing wrong?
(details please)
The biggest problem I have is just trying to read the code with the excessive and inconsistent indentation. 4 SPACEs rather than 2 TABs for each indent level is enough.
As for C++, remove #include<iostream>
and if there are any new errors, that's C++ code. Change it accordingly. If you then compile it with a .C extension, C++ code will be flagged as errors.
hello. i make a program for bus ticket reservation and i want to put a seat number in there. so if want to loop the program, and if i pick the same seat number, the program will tell me the seat is taken. is it possible to save information before looping the program?
Of course. Have a 2D array of seats with all zeroes. When a seat is chosen, put a 1 in that array position that corresponds to that seat.
I will gladly be more specific; allow me to take this opportunity to remind ye' that YOU ARE POSTING C CODE IN A C++ FORUM. I don't go to a Java forum and post Pascal. I don't go to a C# forum and post QBasic. I don't go to McDonalds and ask for a Whopper. Why do people insist on posting C code up in here and expect results...???!
C is C++. When an instructor in the C++ course starts with the easier (to them) syntax of C, they teach C under the guise of C++. The student doesn't know any better so they post here. This is perfectly acceptable so stop getting you knickers in a snit. It's not worth it.
If you enter the number 12, how many keys do you actually hit? 1, 2, 3? If you actually read the number (12) what's left in the input buffer to be read at the next input?
2 things:
1) stop using red -- it's annoying an unnecessary
2) format your code better. It's close to unreadable.
These are codes that do absolutley nothing, except to show whart you can do with to much time on your hands. Oh the silliness
And your point?
I'd do something similar to Clinton's idea read a line with getline do the find like he does if found do the fprintf there is no need for vectors based on your post and i'm sure they are beyond your knowledge people here think vectors are the best thing since the wheel and never realize that new students probably have never heard of them and always suggest them to the student's chagrin also not that reading text like yours with no sentence structure is very difficult to read please use proper english syntax including proper punctuation this is not im
Thank you, WaltP. It works....
Yeah, I know... :icon_wink: :icon_mrgreen:
Think WaltP just posted wrong!
No, he didn't post the code until after I saw his first and only post at that time.
You forgot the ; on line 6.
The IF in line 8 cannot be in all capital letters.
And you misspelled PRINTF
plz tell me how can i add purchase in choice menu ...
Do you seriously not know how to add PURCHASE to the menu?
...and it gets added to the program ...
Follow the pattern set forth for the other items.
...and it works as a software ...
No idea what this means.
...and keep the record feeded in it.
Output the record to a file to be read next time the program starts.
a <a.in >a.out
At the command line,
< will input a file as if it was from the keyboard
> will take the stuff that goes to the screen and put it a file instead
Skip all even numbers. That will cut your loop in half: for(i=3;i<=root;i+=2)
Sorry, but most of us won't download files. Everyone here posts their code (using CODE tags) and asks specific questions to get help. See the Member Rules.
I have a bunch of floats and I need to convert them to string to use Send command to send to a Receiver. However, I been trying to code like below where long1deg is a float.
char long1degC = long1deg;
Orchar* long1degC = new char[30]; float long1deg= 2.4567F; sprintf(long1degC, "%.4g", long1deg);
but I always get errors every time. Any pointer will be really appreciated.
unfortunately my psychic powers aren't working tonight so I am unable to divine what the errors are. Maybe you should tell us.
And you should be using CODE tags, not ICODE tags.
The simple way to put it is that the poor are the ones who benefit most from the social programs that take up the largest chunk of the US budget (public education, medicare, EI). So if you raise their taxes you'd be raising the costs of all those programs by the same amount if you intend to prevent their already low standard of living from slipping farther.
Never suggest raising taxes at all. Just that the rich pay their fair share. That will effectively add a lot of tax dollars collected and the tax rates could actually be lowered.
And since (I assume you'll agree with me on this point) gov't programs are not as efficient as leaving the money in their pocket to begin with you'll actually lose money by raising taxes on them.
I'll agree partially.
1) Yes, gov't programs are not efficient.
2) No, leaving the money in their pocket is not efficient either. From first-hand knowledge the poor drive the Cadillacs rather than buy needed items like food, and you get one guess which income bracket buys the most lottery tickets.
Therefore it is more cost-effective to tax the rich (fewer people to chase down and forms to process for the same amount of revenue) than to tax the poor.
Sure it's more effective to just tax the rich at a higher level -- if you ignore the long term outcome.
John is a wealthy business owner. He makes $1,000,000 a …
First off, stop apologizing! Not everyone was born a programmer. It's OK... :icon_wink:
Second, you need to think about what you are doing. What are the limits of your loop - from what value to what value? Where do the values come from? Where are they now calculated?
Third, when calculating running totals (values in each line or the table), the values used in these calulatons must be modified. What values are you using to calculate these totals and where are they modified?
You might want to sit at a desk (no computer) and actually do a few of the calculations by hand. If you don't understand how the numbers interact with each other, you have no idea how to program the task. What values are computed for a line? Do these computed values affect the next line in the table? How?
You can't just throw equations into code and pray it works. You must understand the concepts in order to write the code properly.
I tried putting my calculations inside the for loop and now my program does not run at all. It seems the more I try to correct it the more I get confused...
Since we're not the Psychic Programmer's Forum, we can't really help you understand what you did wrong based on the information given.
That's because you don't do any calculations within the loop. All you do is display the values you calculated before the loop starts.
Before posting "how do I fix it", think...
OK....
So open the file in the correct way in the correct place, do the read or write, close the file.
Test the code.
If it still doesn't work, post an explanation of exactly what happened and the code you ran.
I think I already said that... Any constructive advice?
OK... You asked for it :icon_twisted:
No! No labels! Please!
Why. Labels, though unnecessary, are benign. They don't do anything.
Labels are about the worst programming you can do.
I can think of many other things worse...
It makes code unreadable,
Actually, they can help document the code. Not as well as comments, but a well thought out label name can define code sections.
and is always solvable using loops.
Labels solve nothing.
Labels can often crash your program,
Labels cannot possibly crash a program. They just define a name to a place in the code.
and are impossible to debug,
Nothing to debug, they do nothing.
because of the jumps ni your code.
Only if you use goto
to jump to them.
Happy? :icon_wink:
[boilerplate_help_info]
Posing requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code. If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen. We can't read your mind. You need to tell us what happened.
[*]To [b]not[/b] ask for code. We are not a coding service. We will help you fix your code.
If anyone posts working code for you, they are a …
Well, there's the switch
statement:
#include <stdio.h>
int get_index(int value)
{
switch(value)
{
case 0:
case 1:
case 2:
case 3:
return 0;
case 4:
return 1;
case 5:
case 6:
case 7:
case 8:
return 2;
case 9:
return 3;
case 10:
return 4;
default:
return 0;
}
}
int main(void)
{
int numbers[] = {1, 2, 3, 4, 5};
int i;
for (i = 0; i < 10; i++)
printf("numbers[%d] == %d\n", i, numbers[get_index(i)]);
return 0;
}
OK, here is what I'm going to do: Below is code that will do what you want, just copy and paste it into your compiler. However, you will still have to figure some things out.
But first, you need to understand how the goto statement works - it's easy. Goto is a statement that causes program flow to jump to a label, like so:do_again: //This is a label and ends with a ":". cout "I'm in a goto loop!"; goto do_again;
Do NOT Follow this advice!!!!
1) We do NOT - repeat NOT - recommend bad coding practices here!
2) We do NOT - repeat NOT - write the code for people!
3) We suggest - repeat suggest - corrections they can apply to their own code!
4) When posting illustrative code segments it is properly formatted code so people can learn the proper techniques! Yours is terrible. Doesn't matter where it started from. Reformat.
If you are going to recommend such bad practices there are other forums to peddle you bad advice. Here, we help people learn to code properly, and goto
is rarely proper. And what's the instructor going to say when he gets a program with GOTOs? Immediate fail I'll bet. Especially since he hasn't taught it.
So leave your GOTOs to yourself and never bring them up again. And do NOT post working code "that will do what you want, just copy and paste it into your compiler". …
first thing,
Initialise the variables that you have declared. If you don't, then they contain garbage values.
Not necessary if the first thing you do with any variable is read or load a value into it.
Ya I always do this kind of thing... I guess the only difference between C and C++ is the way they handle output and input. C++ has cout and cin (which I find simpler than scanf and printf in C). So why try to change the code when only the Input Output is different...
If that's the only difference, why use C++ at all? Obviously you don't really know the difference between them. It's much more complicated than input & output, which is only a minuscule difference.
You now have to look at each character and decide if it's a
1) letter
2) digit
3) operator
And set values accordingly. For example, you could do something like:
string variable[10]; // hold 10 variable names (a, b, c, etc)
int varindex; // the index of the variable name from the line
float values[10]; // the value of each variable above
char operator; // the operator on the line being read
Then when you get to the end of the line, call a function to process the data you read.
The main problem here is that you need to test for high or low input ranges, but you are dealing with strings. The string "15000000" has no relation at all to the value of 15 million. It's just a string of symbols, no different than "Hello World". So you are going to have to change the varible stdIDInput to type int instead of type string.
Once you do that, then stdIDInput is an integer value that you can simply test for high or low values with an if statement, and loop back around with an error message and to re-enter the stdIDInput.
All completely worthless crap! Please ignore this advice. All this does is test a range. We still need to test exact IDs. And converting to int is a complete waste of time.
Also, just in case you didn't know, you can beep the beeper whenever an input in out of range, just add escape a in your cout statement.
More useless information (and annoying to the user).
So if you choose the search option, the screen should clear and you would have the search screen.
Another annoying piece of advice. Since Standard C++ cannot clear the screen, and most users find clearing the screen unnecessary and annoying, completely ignore this advice, too.
Well, here is a clue: That if statement is in a loop, and every loop is a test for a match and if the first loop doesn't match then "not found" would print, …
Well, if you check your studentID's and it's not there, output "Not Found".
Think about it. Where would you do this?
I prefer not to go after openings, I don't have enough reputation points yet
Rep points don't count in the Geeks Lounge so your rep points won't be affected. So go for the openings. It makes the lounge more interesting :icon_wink:
To begin with:
[boilerplate_help_info]
Posing requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code. If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen. We can't read your mind. You need to tell us what happened.
[*]To [b]not[/b] ask for code. We are not a coding service. We will help you fix your code.
If anyone posts working code for you, …
Did you post your execution so we can see what went wrong? That usually helps.
I don't think taxing the rich more is wrong at all, particularly because some people are struggling to survive.
So taxing the rich prevents people from struggling. You obviously don't live in the US. Otherwise you'd know that the extra taxes will not go to struggling people.
It's like a mandatory conscience, instead of donating to a homeless shelter the government steals the money and then takes part of it, and gives the rest to the starving/homeless.
You're dreaming. They build bridges to nowhere. Rather than making sure our borders are safe and adding to the 40,000 border guards, they pay 120,000 IRS agents to police their own people instead, finding those that made mistakes trying to understand the convoluted tax laws. They pay people to make the tax laws more complicated rather than making them simple. They pay retired congressmen and representatives a pension of 100% of their last wage.
Where's all this money come from?
Could give tax breaks to the wealthy for donating to charity then?
They already give tax breaks for this. We all have this break. Schedule A lines 16-19.
What we need is for the rich to pay their fair share and stop being given huge loopholes to lower their taxes.
Last year my federal tax bill ... was $6,938,744. That sounds like a lot of money. But what I paid was only 17.4 percent of my taxable income -- and that's actually a lower percentage than was paid by …
thank you, but that not.I mean system date in OS.
If it's not the system date, what is date? What's wrong with using it?
[boilerplate_help_info]
Posing requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code. If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen. We can't read your mind. You need to tell us what happened.
[*]To [b]not[/b] ask for code. We are not a coding service. We will help you fix your code.
If anyone posts working code for you, they are a …
No you don't. You want to use fgets()
to keep it safe. Here's why
And if the code already works, why change it to be simpler? You will (undoubtedly) break it and have a difficult time fixing it.
May be but I m not familiar or learned get or put yet. Is there any other way to do it???
So? Why do you need get
and put
? What needs to change in your code to make it C rather than C++?