- Strength to Increase Rep
- +6
- Strength to Decrease Rep
- -1
- Upvotes Received
- 5
- Posts with Upvotes
- 5
- Upvoting Members
- 5
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
49 Posted Topics
Re: [QUOTE=Tommybb;759674] .... Are there any good online sources you all would recommend for a beginner? Thannks, Tom [/QUOTE] The following site is good, but of course won't cover much. I personally learn only from the internet, and make programs for fun and complex calculations. Whenever I want to do something … | |
Re: Binary operations are operations between two variables (like a+b, a-b, a^b, a/b etc.). Unary operations are operations on one variable (a++, a-- ...) | |
Re: Look at this link: [url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1031963460&id=1043284385[/url] The last method is probably what you're looking for. | |
Re: In case you like math, you can try the following site: [url]http://projecteuler.net[/url] | |
Re: Two things: First, you forgot to add the first number to the total. Second, with [icode]while(!source_file.eof())[/icode] you run through the last line twice. Therefore, instead of 10+20+40+10+12 = 92 you get 20+40+10+12+12 = 94 | |
Re: Look at the code here: [code] if (pos [color="red"]![/color]= -1) { goto badsearch; } [/code] I think you meant: [code] if (pos [color="red"]=[/color]= -1) { goto badsearch; } [/code] Another thing is that string::search() returns string::npos if the search function does not find what it was told to find, and … | |
Re: I don't understand - why do you have the numbers input as 'int'? Why don't you have the numbers input directly into a string and then use the operator [] to move through the digits and count values? I think it could be much more efficient - just run a … | |
Re: In addition to the above posts: 1) The user has no chance to input the second number. Better add [icode]cin>>dsecondnumber;[/icode] after the user is told to input the second number. 2) In your [icode]case[/icode] statements the output is always [code]cout<< " The Answer is:"<< dfirstnumber << (operator) << dsecondnumber << … | |
Re: Why not use the built-in [URL="http://cplusplus.com/reference/algorithm/random_shuffle/"]random shuffle()[/URL] function from the header [icode]<algorithm>[/icode]? | |
Re: Look at your while loop: you closed it before it started: [icode]while(ordnum != 99999);[/icode]. Just remove the semicolon right after the [icode]while(ordnum != 99999)[/icode] and everything should be fine ;) | |
Re: Change this line: [icode]cout<<fly.freeSeat;[/icode] to this: [icode]cout<<fly.freeSeat[color="red"]()[/color];[/icode] Remember that [icode]freeSeat[/icode] is a function ;). Edit: I guess Narue was faster :) | |
Re: Add [icode]Password="";[/icode] before [code=c++] while(encrypt != 13) { Password.push_back(encrypt); cout << '*'; encrypt = _getch(); } [/code] That's because when the user enters a wrong password you keep [icode]Password[/icode] with the wrong password and just add characters to it. You need to empty it before. | |
Re: That's weird - it works perfect for me. | |
Re: What about a linked list? Or alternatively, you could store all the class instances in an array with as many elements as the the user inputs, and to check which instance has the student's ID run a loop through all the indexes. An example to make it all clearer: [code=c++] … | |
Re: The function is expecting an int[] (array/pointer) type and you pass an int, instead you should write the function as: [icode]void bookInfo(char[14],char[51],char[31],char[31],char[11],int,double,double);[/icode] It would also be better if you used strings from the <string> header instead of arrays of [icode]char[/icode]s. | |
Re: [QUOTE=iammfa;844199]Hi all, what is the bug in the following code: [code=c++] #include <iostream> #include <string> int main() { string str = "Hello World!" cout << str << endl; cout << float x = 5.0f * str << endl; int 65Num = 65; cout << "65Num = " << 65Num << … ![]() | |
Re: [code=c++]outputFile<<"Name: "<<Pname<<" "<<outputFile<<"Date:"<<TDate<<endl;[/code] You output what outputFile returns. This line should be [code=c++]outputFile<<"Name: "<<Pname<<" "<<"Date:"<<TDate<<endl;[/code] | |
Re: I'm guessing it's because of the getline() function. When I replace the [code=c++] if(AWUTD=='y'||AWUTD=='Y') { cout<<"Please Specify:"<<endl; getline (cin, AWUTDspecification); } [/code] with [code=c++] if(AWUTD=='y'||AWUTD=='Y') { cout<<"Please Specify:"<<endl; cin>>AWUTDspecification; } [/code] it works better. I suggest that you read the following ReadMe thread: [URL="http://www.daniweb.com/forums/thread90228.html"] How do I flush the input … | |
Re: [QUOTE=vmanes;761217]Where do you get an 8 byte long int? It's 4 bytes everywhere I've seen.[/QUOTE] A [icode]long long int[/icode] (signed/unsigned) is 8 bytes. [icode]cout<<sizeof(long long)[/icode] | |
Re: Please use code tags. Otherwise it'll be hard for us to tell you on which lines your mistakes are. | |
Re: You'll have to re-write everything. Just make a new file, read the file you want, and write the lines to the new file, with the changes you want. Afterwards, erase the old file and rename the new file to the old file's name. There's something similar (erasing a line from … | |
Re: What do you mean? Do you want the blocks to appear in lines, like that?: [code] ****** ****** ****** ****** ****** * * * * * * * * * * * * * * * * * * * * ****** ****** ****** ****** ****** [/code] If you do, … | |
Re: It doesn't matter that 'i' doesn't exist when main() ends and the thread is using it, simply because when main() ends the whole program shuts down, including the threads. | |
Re: The computer doesn't recognize when a cell is occupied because you didn't tell it to. You're making a check only on board[5][x]. You should use a loop to check which is the the highest place available and just then test it. | |
Re: A much clearer method would be [icode]rand()%x[/icode], where x is the number you want. For example, [icode]rand()%7[/icode] will return a random number between 0 and 6, and the code [icode]rand()%7+1[/icode] will return a value between 1 and 7. If you want the numbers to be as random as possible, add … | |
Re: [url]http://www.daniweb.com/forums/post31214.html[/url] This link should help you. It teached me well how to use ifstream objects. | |
Re: We won't do your homework. You should provide us some code so we can know you've at least tried. [url]http://www.daniweb.com/forums/announcement8-2.html[/url] | |
Re: Why should a constructor fail? When you declare a constructor, all the instances of the class will have to use it, or variations of it (if you declare some). | |
Re: [code=c++] for(x=0;x<s.length();x++) { if((s[x]>'9' || s[x]<'0') && s[x]!='.') { input_type=IS_STRING; break; cout<<" Its an integer "; } else if(s[x]=='.') { if(!DotReached) DotReached= true; else { input_type=IS_STRING; cout<<"ITs a Float"; break; } } } [/code] Line 6: How do you want the program to output "It's an integer" when there's a … | |
Re: I think it would be much smarter to use the built-in function from <algorithm> header file -- random_shuffle(): Run a loop and insert to the array all the numbers between 1 and 10,000, then call random_shuffle() to shuffle them. An example code: [code=c++] #include<iostream> #include<fstream> #include<algorithm> using namespace std; int … | |
Re: [QUOTE=jeevsmyd;756974]sorry I dont understand you.. i have that code in my programme..! :)[/QUOTE] Functions should be declared outside the main() function. Example: [code=c++] long int factorial(long int); int main(void) { // blah blah blah } // main() ends /*now you can declare another function. Can also be before main(), but … | |
Re: I think the following snippet is more efficient (using the ideas of the above code by Chris): [code=c++] #include<iostream> #include<cctype> #include<string> using namespace std; int main(void) { int InputValue=0,x; string Input; cout<<"Input a string to check its value:\n"; getline(cin,Input); for(x=0;x<Input.length();x++) { if(isalpha(Input[x])) { InputValue+=toupper(Input[x])-'A'+1; cout<<toupper(Input[x])-'A'+1<<"+"; } } cout<<"\b="<<InputValue<<"\n"; system("pause"); return … | |
Re: Switching from capital letter to small letter and vise versa is easy: The letter is capital if it's between 'A' and 'Z' (inclusive)(ASCII symbols' values are in order) and the letter is small letter if it's between 'a' and 'z' (inclusive). So, to change a small letter to a capital, … | |
Re: So, you actually want to round up when (the number) mod 1000 is equal or greater than 500, and down if (the number) mod 1000 is less than 500. An example to how you could write it: [code=c++] #include<iostream> using namespace std; int main(void) { int x; cout<<"Enter a number … | |
Re: This thread may help you: [url]http://www.daniweb.com/forums/thread161801.html[/url] | |
Re: Why bother with the whole word when you only need the first letter ('m' or 'f')? [code=c++] if(s[0]=='m' || s[0]=='M') // do what you want for male else // do what you want for female [/code] | |
Re: Input to a string, then call a function to check whether it the input string has only digits (and '.', '+' and '-' as first only). If it really has only digits, it's a number. If it has a dot, it's a floating-point number, else it's an integer. If you … | |
Re: I also had a big problem understanding pointers, but it's not that hard: pointers are just like any other variables when you use the asterisk (*) before them - which leads to the value in the address they hold. They're useful because, just how serkansendur said, you can save computer … | |
Re: [icode]private: double rad[b][color="red"]ui[/color][/b]s;[/icode] I think you swapped these two letters | |
Re: " This program models a simple calculator which can add, subtract,multiply,divide, power" I don't see any power operation in the program. If you meant to the ^ operator, it doesn't do power (at least in c++). It's an operator which works on bits. For power you need to implement a … | |
Just wanted to know... is there any variable in C++ that can hold larger numbers than [icode]unsigned long long int[/icode], or is it the largest variable? Thanks in advance :P | |
Re: [QUOTE=Benbon86;710639]I actually found this site while trying to fix my awful coding so no, I did not have a chance to read the site's stickies and for that, I apologize. I've been trying to figure this out for the past three hours and I know this is pretty simple but … | |
Is there a way to #define something as a #warning? I tried using the following code, but it gives me an error: 'warning' undeclared (first use this function) This is the part of code where the error appears: [code=c++] #define something #warning This is not a standard function! int main(void) … | |
Re: Heh, funny one. I think it's something that's already declared in strcmp. | |
Re: [QUOTE=Traicey;707204]I dont know what would I do without u, thanx man but can u provide me with a sample code so I can just replace[/QUOTE] [url]http://www.daniweb.com/code/snippet777.html[/url] | |
Re: You can add a time limit by adding something like: [code]clock_t StartTyping;[/code] and every time the game runs do: [code]StartTyping=clock()[/code] Then, before checking if the answer is correct, check if it was on time. Example: [code=c++] if((clock()-StartTyping)/CLOCK_PER_SEC>/*number of seconds here*/) { cout<<"It took you too long!"<<endl; cin.get(); exit(0); } else … | |
Re: I'd suggest that you use the [icode]clock() [/icode] function. Examply of use: [code=c++] #include <ctime> #include <iostream> #define SECONDS number of seconds here.. using namespace std; int main(void) { int guess; cin>>guess; if(clock()>SECONDS*CLOCKS_PER_SEC) return 0; return 0; } [/code] Note: clock() returns the number of milliseconds passed since the program … | |
Re: Remove the [icode]long[/icode] before the [icode]float[/icode] and change [icode]%lf[/icode] to [icode]%f[/icode]. Then it'll work. Also, it'd be clearer if you'd intialize [icode]j[/icode] when declaring it, and not some lines after it. | |
Hey there, I'm trying to use the SetSuspendState() function to hibernate the computer, but I have no idea what parameters I should send to it. The prototype is "BOOLEAN WINAPI SetSuspendState(BOOLEAN, BOOLEAN, BOOLEAN);" Since I'm a somewhat beginner in c++ programming, I don't really have an idea what BOOLEAN means … |
The End.