Forum: C++ 25 Days Ago |
| Replies: 4 Views: 481 int xMin = -10;
int xMax = 10;
double xData[xMax - xMin];
xData contains 20 elements starting from 0 to 19.
int counter = xMin;
for (counter; counter <=xMax; counter++) { |
Forum: C++ Aug 4th, 2009 |
| Replies: 24 Views: 770 My bad :(
You are totally right. |
Forum: C++ Aug 4th, 2009 |
| Replies: 24 Views: 770 You can't simply compare 2 strings with operator ==. There is a function in library <string> called strcmp().
Syntax:
int strcmp(string1, string2)
Return:
Return 1 if string1 >... |
Forum: C++ Jun 29th, 2009 |
| Replies: 3 Views: 210 while (tryanother = 'y')
Change = to == |
Forum: C++ Jun 27th, 2009 |
| Replies: 13 Views: 570 Initializing the elements of an array a1 and size n randomly, so that its elements have values between [1-45].
I think the assignment want us to create an array with random size in runtime. |
Forum: C++ Jun 27th, 2009 |
| Replies: 13 Views: 570 Posting the whole assignment will not help you or help us know what you have problem with. If you do not understand the logic, tell us which part that you don't understand. Tell us more about what... |
Forum: C++ Aug 15th, 2008 |
| Replies: 13 Views: 2,520 It is quite simple. User input the value into number not A[number]. So it should be sum = sum + number. |
Forum: C++ Jul 17th, 2008 |
| Replies: 8 Views: 814 Mathematically, you can just constantly substract the dividend with divisor and count it until the dividend become smaller than the divisor. If dividend become 0 after it's been constantly... |
Forum: C++ Jul 17th, 2008 |
| Replies: 6 Views: 975 Of course you can have multiple of them. However, try to avoid using it as much as possible since most of the time goto can be replaced with a loop. For some case such as break multiple-level of... |
Forum: C++ Jul 17th, 2008 |
| Replies: 6 Views: 975 Then use goto
for (int a=0; a<10; a++) {
for (int b=0; b<10; b++) {
for (int c=0; c<10; c++) {
if (b == 5)
goto endloop;
}
} |
Forum: C++ Jul 16th, 2008 |
| Replies: 4 Views: 417 I haven't read all of your code because it is hard to read wihtout code tag. However, I think your sort should be in this way:
string temp;
for (int j = 0; j < capacity-1; j++) {
for(int i... |
Forum: C++ Jul 16th, 2008 |
| Replies: 4 Views: 417 You have sorted your income array and that is the reason why. |
Forum: C++ Jul 16th, 2008 |
| Replies: 19 Views: 1,490 I think you didn't provide enough information about your project. For example: how the loop produce the combination? how will you compare those combination? what is the purpose of your combination?... |
Forum: C++ Jul 13th, 2008 |
| Replies: 11 Views: 899 return number * (byThePower(number , power - 1));
I don't know how to explain it, so I would rather show how it process: Let say power = 4
Number to return = number * byThePower(number, 3)
... |
Forum: C++ Jul 13th, 2008 |
| Replies: 11 Views: 899 I would write it like this: (this code works only when the power is a positive number)
int byThePower(int number, int power)
{
if (power >= 1)
return number * (byThePower(number ,... |
Forum: C++ Jul 13th, 2008 |
| Replies: 11 Views: 899 int ans,num,power1 ;
num =1;
Why you declare something that you didn't use?
number=number*number;
power--;
return(byThePower(number,power)); |
Forum: C++ Jan 26th, 2008 |
| Replies: 20 Views: 2,458 I don't feel that your code works 100% correctly. What's happen when the first digit is number 9? 9 < 9 == false. |
Forum: C++ Jan 20th, 2008 |
| Replies: 9 Views: 907 a++ mean a = a + 1.
so (!a)++ mean !a = !a + 1 which !a is not a variable. |
Forum: C++ Jan 7th, 2008 |
| Replies: 6 Views: 1,792 std::cout and std::endl, I believe. |
Forum: C++ Jan 4th, 2008 |
| Replies: 8 Views: 741 cin.getline(p,50);
The reason why it does read only 49 characters because the computer need the last character to be a NULL character. |
Forum: C++ Jan 4th, 2008 |
| Replies: 6 Views: 722 You need 3 files:
golf.h contains the functions declaration.
golf.cpp contains the definition of the function in golf.h
main.cpp contains the main() function |
Forum: C++ Jan 1st, 2008 |
| Replies: 7 Views: 854 if (board[rownum-1][colnum-1] == 'X' or board[rownum-1][colnum-1] == '0')
What language are you using?
char board[ROWS][COLUMNS]=
{ {'.' , '.' , '.' , '.' , '.' , '.' , '.' , '.' , '.' ,... |
Forum: C++ Jan 1st, 2008 |
| Replies: 10 Views: 1,259 The file that you attempt to read is not exist. To track this kind of error, I would suggest you to use std::cout inserting method.
void ReadFile()
{ char fname[13],ch;
cout<<"Enter... |
Forum: C++ Dec 30th, 2007 |
| Replies: 13 Views: 1,304 I truthfully don't know what the problem is. |
Forum: C++ Dec 30th, 2007 |
| Replies: 13 Views: 1,304 Can you post a few lines of code around the error line? |
Forum: C++ Dec 30th, 2007 |
| Replies: 13 Views: 1,304 Check line 265, if there is missing semi-colon.. |
Forum: C++ Dec 30th, 2007 |
| Replies: 16 Views: 2,995 for(int i=1 ; i<51 ; i++) {
{
cout<<setw(3)<<alpha[i-1]<<" ";
if( (i+1)%10 == 0)
cout<<endl;
}
} |
Forum: C++ Dec 30th, 2007 |
| Replies: 16 Views: 2,995 It should be:
if( (i+1)%10 == 0)
Because i was started from 0 |
Forum: C++ Dec 30th, 2007 |
| Replies: 16 Views: 2,995 After you successfully initialize your array, you create another loop for print each element of your array. Every 10 elements, you insert the newline character. (Hint: everytimes the counter is... |
Forum: C++ Dec 29th, 2007 |
| Replies: 16 Views: 2,995 If you want to use only one loop, you don't need to use condition.
for(int i =0; i<25; i++) {
alpha[i] = i * i;
alpha[49-i] = (49-i) * 3;
} |
Forum: C++ Dec 27th, 2007 |
| Replies: 30 Views: 2,899 Of course. If I were you, I would seperate the code into 3 files: stack.h, queue.h, and main.cpp |
Forum: C++ Dec 27th, 2007 |
| Replies: 30 Views: 2,899 Salem's avatar told you all about it.
#include<conio.h>
#include<stdio.h>
You are using C header files rather than C++ header files. |
Forum: C++ Dec 27th, 2007 |
| Replies: 30 Views: 2,899 void main()
{ intro();
menu();
}
Non-standard code. |
Forum: C++ Dec 26th, 2007 |
| Replies: 30 Views: 2,899 Don't worry, I would never comment that much in my project, and the comments look nicer in gray colour than in green colour. |
Forum: C++ Dec 26th, 2007 |
| Replies: 30 Views: 2,899 I know that my code is over-commented; however it is very self-documented. |
Forum: C++ Dec 26th, 2007 |
| Replies: 30 Views: 2,899 Self-document code is not only comments what the code does but also the concept of the code. To give you an idea of how to comment, I write a small example of code with comments. (I'm not a... |
Forum: C++ Dec 26th, 2007 |
| Replies: 11 Views: 1,736 It depends; the bigger the number is, the faster the running till sqrt(n) perform. Another thing, all the prime number, except number 2 and 3, are in this format 6k+1 or 6k-1; however, not all the... |
Forum: C++ Dec 26th, 2007 |
| Replies: 11 Views: 1,736 Why make your code so complicated? The most basic concept of finding prime is to test from 2 until number-1. Once you find the divisor number of that number, then you are also able to find the factor... |
Forum: C++ Dec 25th, 2007 |
| Replies: 4 Views: 590 More comments are needed to be added.
/*********************************
* What is the title of your program? *
* What is the purpose of this program?*
* Written by who? ... |
Forum: C++ Dec 24th, 2007 |
| Replies: 5 Views: 860 #include<iostream>
float celsius_to_fahrenheit(float);
int main()
{
float fahrenheit;
float celsius=22.5;
fahrenheit=celsius_to_fahrenheit(celsius);... |