6,741 Posted Topics
Re: With single digits all you need to do is subtract the character '0' from the value. For mutidigit numbers you need to perform a conversion, and the easiest way to do so is with strtol (in <stdlib.h> for C or <cstdlib> for C++), sscanf (recommended only for C), stringstream (for … | |
Re: >scanf("%d,&n"); >n = 0; This assignment is suspicious. >prime = 1; >while(prime < n) 1 is not less than 0; your loop will never execute. | |
Re: >Please give me any suggestions on the program. >Product1, // declare indentifiers >Product2, TotalSeconds; Bad form. Ending a physical line with a comma so that you can use a single line comment and continue the logical line on the next physical line is poor style. >Seconds = Usertime.substr(SecondC + 1, … | |
Re: >"no operator defined which takes a right-hand operand of type 'const char' Post your code. >when you type name you hit space and that cin will acknowledge the space being there? cin's >> operator ignores whitespace unless you tell it to do otherwise. The best option for single line input … | |
Re: I'm never going to answer another question of yours again. Clearly you have no respect for the people that volunteer their time to help you. First you bump your thread before a satisfactory amount of time has passed (a few days I could understand, but not less than 30 minutes), … | |
Re: Add a simple test before you print to the file: [code] if ( in == ' ' ) continue; [/code] | |
Re: So do you have a specific question or were you expecting us to write a textbook on the subject for you? :rolleyes: | |
Re: >#include <iostream.h> If you can use the string class then you can stop using these old headers. >#include <cstring.h> Either you're using an old, nonstandard header, or this should give you a compiler error. >void main() No matter how old your compiler is, main always returns int. This has always … | |
Re: You can open up a command line prompt and run the program that way, but the more common solution is to ask for input at the end of the program so that a blocking read pauses execution: [code] #include <iostream> using namespace std; int main() { // Your program here … | |
Re: >(1) The brief history of evolution of 'c' language. There's no such thing as a brief history of C. However, Dennis Ritchie's web site has a nice description of it, so you can try to summarize that. >(2)The advantages of this language among other available languages Advantages and disadvantages differ … | |
Re: >If you can help email me If you're not interested enough to come back and check for replies then I'm not interested enough to help you with your problem. | |
Re: >int result = (int) (rand.nextInt()); Should be: [code] int result = (int) (rand.nextInt(num)); [/code] By the way, Sun has a complete API listing for Java that makes a wonderful reference when first learning: [url]http://java.sun.com/j2se/1.4.2/docs/api/[/url] | |
Re: >how do u allow the user to input as many values as they want? You can use a sentinel value that, when read, will terminate the input loop. This sentinel must be a value that is not within the valid range, or all input must be taken as string data … | |
Re: >I'm trying to compare a string to an ArrayList Object. This is your problem. Unless you can figure out a way to convert the ArrayList to a String so that they are comparable, you'll need to manually compare each item individually in a loop. | |
Re: >but not all of my question's have been answerd It's rather difficult to answer "I wana be a l33t g4m3 c0d3r like John Carmack, tell me how to do it!" questions. Get a compiler, get a book, and start from hello world; just like the rest of us did. >:rolleyes: … | |
Re: >Or if anyone has the code which is similiar to my HW will be highly appericated. No, you do your own homework. If you post your code then we can help you with it, but we won't give you the program. | |
Re: [code] if ( pageIndex % 2 == 0 ) { // Even } else { // Odd } [/code] | |
Re: Read a number, set both the min and max to that number. For each new number you read, if it's larger than the max, assign it to max and if it's smaller than the min, assign it to min. | |
Re: >the class has just started using C++ so only simple commands will be acceptable This implies that you want us to do it for you. How presumptuous! Why don't you start by asking a pointed question that DOESN'T start by pasting your assignment. | |
Re: Have you done any research? You realize that the Java API has a Math class with a random() member function that returns a double between 0.0 and 1.0. Once you have that it's a simple matter of multiplying by N to get a random range from 0 to N. | |
Re: >the error is: P,G,and C are unreferenced local variables That's not an error, that's a warning. And if you remove the declarations for P, G, and C, the warnings will go away. | |
Re: [QUOTE=manoj9_5]----------------------------------------------------------- output will be X X because ptr1 point to the var2 and var2 contain value 'x';[/QUOTE] Not necessarily. At that point dereferencing an uninitialized pointer has caused undefined behavior. After that, nothing is guaranteed to work, even if it would otherwise. | |
Re: [code] #include <stdlib.h> ... display_character_at(x, y, rand() % 128); [/code] :) | |
Re: >If you can just help me debug it I'll help, but I'm not going to do it for you. Debugging is what the majority of programming is, so if I did it for you then you would learn nothing. As it is, you didn't specify what the error was in … | |
Re: What are you trying to do with those two functions? It's clearly not a simple factorial or modulo calculation, so unless you describe what the problem is, we can't help. Though I can tell you right now that your power function isn't going to work like you expect. >i=a^b; ^ … | |
Re: I hope you plan on using one of the braindead windowing interfaces, because with typing like that you won't get very far on the command line. :lol: ![]() | |
Re: >ln(x) doesn't work in BC 3.1 Neither does 1/3. Maybe, just [b]maybe[/b] vegaseat was using mathematical notation rather than valid C++ code. :rolleyes: Get a reference and figure out what the equivalent functions are. It's really not that difficult. | |
Re: Start by including stdio.h and making sure your braces match, then we'll talk. | |
Re: The harsh reality is that you'll learn more on your own or on the job than you will from college. Since that's the case, pick the school that will look best on a resume and do all of the following in your spare time: 1) Read, read, read. 2) Practice … | |
Re: >use memcmp Brilliant! No, not really. If not being able to use strcmp is a requirement of the function then clearly it's homework and using memcmp would result in a failing grade. However, I won't make a suggestion other than looping over the contents of both arrays and making comparisons … | |
Re: >is microsoft visual C++ the same as any other C++ programing tool? Yes, if by "the same" you mean it compiles something called C++ that may or may not be the standard definition of the C++ language. Otherwise, no. Compliers and development environments are all different, but if they claim … | |
Re: Nobody is going to download 5 files just to help you. My suggestion is that you remove everything you can without removing the error itself (but if you do, note what you took out). Then you'll be in a better position to debug. Who knows? The code may be short … | |
Re: >It took me about 2 days but I got it lets see if you can do it. >Challenge ends on October 27 the program will then be posted for you viewing Geez, you'd think that people would be more creative than this. Do you want to know how many times … | |
Re: >system("pause"); >put getch(); You know what I find funny? The fact that every time this question is asked, the first two replies suggest the first two absolute [b]worst[/b] options. :rolleyes: system is slow, nonportable, and a serious security hole and getch is the patron saint of nonportable. >What can I … | |
Re: >i couldnt finish it cuz i have 2 exams cal2 and physics 2 tomo.. Tough beans. Learn to start your work sooner or prioritize the homework that's most important and accept the failing grade that you deserve for the homework you're unable to finish. Do you think that when you … | |
Re: >Can anyone out there help me write the "Main" part. [code] #include <iostream> #include <queue> using namespace std; int main() { queue<char> q; char ch; bool match = true; cout<<"Enter a message: "; while ( cin.get ( ch ) && ch != '\n' ) q.push ( ch ); cout<<"Enter another … | |
Re: >1. What exactly is the purpose of white spaces? Whitespace serves two purposes. First, it separates certain tokens that cannot be immediately adjacent. For example, this is valid C++: [code] int i; [/code] But this is not: [code] inti; [/code] At least, it isn't valid unless you've declared a name … | |
Re: >Can someone tell me what is wrong with it? Just about everything. You're also overcomplicating things and it's pretty obvious that you aren't referring to any book on C++ or trying to compile this or you wouldn't have such dreadful syntax errors. Use this as a template: [code] #include <cctype> … | |
Re: >#include<iostream.h> No, not C++. >#include<iomanip.h> Also not C++. >#include<conio.h> Not only is this not C++, it's also only available on a limited number of implementations. >void main() This never has been, and hopefully never will be, correct C++. main returns int. In fact, the old argument of being a lazy … | |
Re: What did you try and where did you search? I get plenty of hits on google for this sort of thing, and several books go over it during their explanation of stacks. | |
Re: Header files are just textual replacement. When you say [code] #include "Person.h" [/code] That line is replaced with the contents of Person.h. In other words, everywhere you include Person.h, you get this: [code] #include <string> class Person { public: Person(char * name = 0,int age = 0); Person(Person const & … | |
Re: The function works properly when I test it. What is it doing that it shouldn't? | |
Re: >I'm really drawing a blank as far as how to setup the function that reads the fractions inputed by the user. It's as simple as reading two integers and saving them in numerator and denominator variables. | |
Re: >int *a = malloc(10 * sizeof *a); [QUOTE=Chainsaw]Most compilers will complain because malloc() returns void* and, in C++, you need to cast void* to the type you are mallocing. Generally, you should use 'new' and 'delete' rather than malloc, for at least these three good reasons: 1) You don't need … | |
Re: ><iomanip.h> is a (deprected) C++ header Nope, iostream.h was removed completely. Deprecated presumes that the header is still valid C++, but not recommented as it might be removed in future revisions. As it is, iostream.h is nonstandard and should be treated as such. | |
Re: >Can someone please help me with a statement to calculate the median when the array is even. Take the median of the two middle items: a[size / 2] and a[size / 2 + 1]. | |
Re: >Which language would be the best intial language to learn to get the most education as a programmer. Python is a good start, so is Java. >BCX is the way to learn it! Funny, in all my years of programming with C++, this is the first time I've heard about … | |
Re: do..while loops end with a semicolon: [code] } while(!infile.eof())[color=red];[/color] [/code] But, tell me what happens when the input file is empty? Your do..while loop will still process a character, but it will be uninitialized and the result is undefined behavior. A while loop is better, but don't use stream.eof() as … |
The End.