Forum: C++ Aug 24th, 2009 |
| Replies: 8 Views: 276 In case you like math, you can try the following site:
http://projecteuler.net |
Forum: C++ Aug 24th, 2009 |
| Replies: 4 Views: 215 Two things:
First, you forgot to add the first number to the total.
Second, with while(!source_file.eof()) you run through the last line twice.
Therefore, instead of
10+20+40+10+12 = 92
you... |
Forum: C++ Apr 17th, 2009 |
| Replies: 19 Views: 834 Look at the code here:
if (pos != -1)
{
goto badsearch;
}
I think you meant:
if (pos == -1) |
Forum: C++ Apr 15th, 2009 |
| Replies: 13 Views: 800 I didn't say it isn't random, I just said he can't ensure that every element moves at least once ;) |
Forum: C++ Apr 15th, 2009 |
| Replies: 3 Views: 224 Change this line:
cout<<fly.freeSeat;
to this:
cout<<fly.freeSeat();
Remember that freeSeat is a function ;).
Edit: I guess Narue was faster :) |
Forum: C++ Apr 15th, 2009 |
| Replies: 13 Views: 800 You can't ensure that this code will move every element at least once because you can't ensure that r=rand()%MAX; won't give the exact value of i.
The code might also replace twice the same... |
Forum: C++ Apr 15th, 2009 |
| Replies: 13 Views: 800 Why not use the built-in random shuffle() (http://cplusplus.com/reference/algorithm/random_shuffle/) function from the header <algorithm>? |
Forum: C++ Apr 15th, 2009 |
| Replies: 10 Views: 512 There are free-to-read tutorials on the Internet as well.
Two good sites:
http://cprogramming.com
http://cplusplus.com |
Forum: C++ Apr 15th, 2009 |
| Replies: 10 Views: 512 In addition to the above posts:
1) The user has no chance to input the second number. Better add cin>>dsecondnumber; after the user is told to input the second number.
2) In your case statements... |
Forum: C++ Apr 14th, 2009 |
| Replies: 7 Views: 670 That's weird - it works perfect for me. |
Forum: C++ Apr 14th, 2009 |
| Replies: 5 Views: 452 Try something like this instead of your while(encrypt!=13) loop:
while(encrypt != 13)
{
if(encrypt!='\b')
{
Password.push_back(encrypt);
cout << '*';
}... |
Forum: C++ Apr 14th, 2009 |
| Replies: 1 Views: 177 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... |
Forum: C++ Apr 14th, 2009 |
| Replies: 5 Views: 452 Add Password="";
before
while(encrypt != 13)
{
Password.push_back(encrypt);
cout << '*';
encrypt = _getch();
} |
Forum: C++ Apr 13th, 2009 |
| Replies: 5 Views: 380 Look at your while loop: you closed it before it started: while(ordnum != 99999);.
Just remove the semicolon right after the while(ordnum != 99999) and everything should be fine ;) |
Forum: C++ Apr 12th, 2009 |
| Replies: 1 Views: 301 The function is expecting an int[] (array/pointer) type and you pass an int, instead you should write the function as:
void bookInfo(char[14],char[51],char[31],char[31],char[11],int,double,double);... |
Forum: C++ Apr 11th, 2009 |
| Replies: 5 Views: 250 outputFile<<"Name: "<<Pname<<" "<<outputFile<<"Date:"<<TDate<<endl;
You output what outputFile returns. This line should be outputFile<<"Name: "<<Pname<<" "<<"Date:"<<TDate<<endl; |
Forum: C++ Apr 11th, 2009 |
| Replies: 5 Views: 352 There are a lot of "bugs" in your code.
Frist, you miss the using namespace std; line before the main() function, so the compiler might not recognize cout and string.
You also missed a semicolon... |
Forum: C++ Apr 10th, 2009 |
| Replies: 35 Views: 1,849 I agree that the sum is different. I said so before. All I say is that the result of what we're interested in, in this case, remains the same - just because the ASCII value of '0' modulo 2 is 0.... |
Forum: C++ Apr 10th, 2009 |
| Replies: 35 Views: 1,849 We're talking about the result of the sum modulo 2. The result is the same. |
Forum: C++ Apr 10th, 2009 |
| Replies: 35 Views: 1,849 Nope. It doesn't change the answer of Sum%2 simply because '0' mod 2 = 0.
If x=y (mod n), and z=0 (mod n), x+z will still equal y (mod n). |
Forum: C++ Apr 10th, 2009 |
| Replies: 35 Views: 1,849 ASCII '0' is 48, '1' is 49... '9' is 57 - '0' mod 2 remains 0, '1' mod 2 remains 1, ... , '9' mod 2 remains 1. |
Forum: C++ Apr 10th, 2009 |
| Replies: 35 Views: 1,849 It's working for determining if the sum is even or not. The Sum mod 2 remains the same. |
Forum: C++ Apr 10th, 2009 |
| Replies: 35 Views: 1,849 Running a loop for such a purpose will look like this using mathematical operations:
unsigned short int a,Sum=0;
a=12522;
while(a)
{
Sum+=a%10;
a/=10;
} |
Forum: C++ Apr 10th, 2009 |
| Replies: 35 Views: 1,849 When you don't need to do calculations with the number there's no reason for doing the mathematical operations on it - you have the possibility to separate the characters more easily usign strings. |
Forum: C++ Apr 10th, 2009 |
| Replies: 6 Views: 296 I'm guessing it's because of the getline() function. When I replace the
if(AWUTD=='y'||AWUTD=='Y')
{
cout<<"Please Specify:"<<endl;
getline (cin, AWUTDspecification);
}
with |
Forum: C++ Apr 10th, 2009 |
| Replies: 35 Views: 1,849 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?... |
Forum: C++ Dec 23rd, 2008 |
| Replies: 8 Views: 2,063 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... |
Forum: C++ Dec 20th, 2008 |
| Replies: 1 Views: 229 What do you mean? Do you want the blocks to appear in lines, like that?:
****** ****** ****** ****** ******
* * * * * * * * * *
* * * * * * * * * * ... |
Forum: C++ Dec 20th, 2008 |
| Replies: 3 Views: 870 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-- ...) |
Forum: C++ Dec 20th, 2008 |
| Replies: 21 Views: 4,641 A long long int (signed/unsigned) is 8 bytes.
cout<<sizeof(long long) |
Forum: C++ Dec 19th, 2008 |
| Replies: 25 Views: 1,498 Please use code tags. Otherwise it'll be hard for us to tell you on which lines your mistakes are. |
Forum: C++ Dec 18th, 2008 |
| Replies: 6 Views: 579 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. |
Forum: C++ Dec 18th, 2008 |
| Replies: 8 Views: 632 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 I don't... |
Forum: C++ Dec 18th, 2008 |
| Replies: 3 Views: 1,258 A much clearer method would be rand()%x, where x is the number you want. For example, rand()%7 will return a random number between 0 and 6, and the code rand()%7+1 will return a value between 1 and... |
Forum: C++ Dec 17th, 2008 |
| Replies: 4 Views: 353 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... |
Forum: C++ Dec 17th, 2008 |
| Replies: 6 Views: 421 http://www.daniweb.com/forums/post31214.html
This link should help you. It teached me well how to use ifstream objects. |
Forum: C++ Dec 17th, 2008 |
| Replies: 5 Views: 374 We won't do your homework. You should provide us some code so we can know you've at least tried.
http://www.daniweb.com/forums/announcement8-2.html |
Forum: C++ Dec 16th, 2008 |
| Replies: 8 Views: 472 Lines 40-41 - it's a STRING, not a float. I've never heard of a number with two decimal dots.
Also, you didn't end the 'for' loop before the input_type check.
You can see it yourself. |
Forum: C++ Dec 16th, 2008 |
| Replies: 8 Views: 472 That's because you removed this piece of code from your code:
else if(s[x]=='.')
{
if(!DotReached) DotReached= true;
else
{
input_type=IS_FLOAT;
cout<<"ITs a Float"; |
Forum: C++ Dec 16th, 2008 |
| Replies: 8 Views: 472 You have a few errors:
Firstly, the if(input_value==0)..... should be OUTSIDE the 'for' loop, because you want to check what kind of number the input is after you know it isn't a string nor a char.... |