Sorry, You already used new.. I overlooked your code.
vidit_X 29 Junior Poster
vidit_X 29 Junior Poster
YingKang commented: Thanks vidit_x . The error msg is gone now :) +2
Sorry, You already used new.. I overlooked your code.
What error did you get when you try to compile?
For counting the number of characters, the better way is as NathanOliver suggested or
int length;
for(length=0;charArray[length]!='\0';length++);
And now about your code, it won't work.. because your are creating a new array at compile time when the value of counter is 0.
Write a function named getString that has a local char array of 80 elements. The function should ask the user to enter a sentence, and store the sentence in the array. Then the function should dynamically allocate a char array just large enough to hold the sentence, plus the null terminator.
You need to allocate memory using new.
This will, with a litte modification. You should break the loop as soon as it finds a null. But remember it will also count spaces.
if (charArray[i] != '\0') {
counter++;
} else
break;
A character array is terminated with a null('\0') character and the content after that doesn't matter. It will be some random data.
You can use this instead..
cin.getline(charArray, 80);
What do you mean by removing the necessary elements from an array?
Do you want to output increasing elements in an array and remove the smaller ones that comes after them?
Ok, I tried to fix it using the code that vidit x stated but there were too many errors. do I put the code after cin >> years?
How can you use it before taking the number of years from user? It cannot predict.
Problem is not in your code but your logic. The expected output seems to be using compound interest but you implemented simple interest. Try..
float raisep = (raise/100);
for(int i = 0 ; i < (years) ; i++)
{
cout << (i+1) << " $" << wage << "\n";
raiseMoney = raisep * wage;
wage = wage + raiseMoney;
}
You are allocating new memory every time you call *pVketor() and I think that's the problem.
Compiler translates your code to native machine code. You cannot have a compiled binary which runs on all the platforms.
True for C and C++. Experts please correct me if I'm wrong.
Is that what you asking?
char alpha='A';
int x=alpha;
Have you defined the function square(int,int,int) somewhere in your code?
You are changing the value of variables(a, b and c) while computing the sum of their digits.
a=a/10;
Then you compare them with the sum.
Use cin.get() twice..
primenum(x);
cin.get();
cin.get();
return 0;
There are other ways, but this one's the easiest.
I think its because you have ORed "R", which is a non-zero value and thus the statement always evaluates to true.
The same problem with your second if statement. And why you using string when you need to store just a character?
You using string without string header...
#include<string>
Where have you defined the overloaded operator << ?
max = num[counter];
min = num[counter];
You are assigning values to max and min from an un-initialized variable and that is the problem. The reason its working with other lines is after the first iteration, the num array gets intialized with the values.
What you can try is .. get a number from the file in the outer for loop, store it in max and min, leave inner for loop as it is and it should work.
In show(), use a loop to traverse through the list till
info->next!=NULL
and increment info every time to point to the next node. In your code, you are not progressing through the list.
There are some errors. The outer while loop ...
while (!infile.eof()
{
.
.
}
will iterate through all the lines of your file. So the values of max, min and sum after the loop will be from the numbers of last line. You lost all the max, min and sum for the previous lines.
The inner for loop is not correct too. Before the outer while loop, you took a number from infile in num and then without using it, you are taking another number in num from infile at the beginning of for loop. So you are loosing the first number from your calculations.
for (int count = 0; count <=7; count++)
{
infile >> num; //You already have a number from line 1 in num
min = num;
max = num;
while (infile >> num)
{
if (num > max) max = num;
if (num < min) min = num;
}
}
Also, your logic for finding max and min is incorrect. The for loop is running 8 times to take 7 numbers from the line. And what is the inner while loop doing?
Is this the complete code? Where are the variable declarations?
Everytime you call getJudgeData(), only one of the variables score1 or score2 or ...
gets a value, not all and between different calls of the same fucntion, the values are not retained.
Also, the call to calcScore() inside getJudgeData() would never be reached. Hope you getting what I mean.
One of the fix is to declare score1, score2 and so on as global variables and then pass them to calcScore() but using global variables is not advised.
Uncomment the friend function declaration
//friend ostream& operator << <T1,T2>(ostream& os, pair2<T1,T2> const& p);
Then edit the function definition for overloaded operator << outside the class to match the friend function declaration. It should work ..
Hey no need to be sorry. What I meant is look at your function signature in declaration. Line 4.
void calcScore()
and the function signature in definition. Line 44.
void calcScore(double one, double two, double three, double four, double five)
Similarly, for the function getJudgeData(). The function declaration and definition should match.
Seems like you would like to overload << operator for your generic class pair2.
You have not declared the overloaded operator function in your class and then you are defining it outside the class.
Either define it inside class or declare it inside class and then define it outside.
The problem is function declarations, you have declared both functions to take 0 arguments -
void getJudgeData();
void calcScore();
Correct them and it should work. And using system("pause") is not good.
@AD, Csurfer - Same here, when I started writing, your posts were not there :)
You cannot use a void returning function with cout.
Since you are outputting something on screen using displayObject(), why not just call it separately. Something like ...
GradeBook myObject( "You got Owned, g++ won't compile" );
cout << "myObject initialized\n";
myObject.displayObject();
cout<<endl;
In Student.h, function declaration of setStudent takes an integer array or integer pointer as argument.
void setStudent(string idIn, string fNameIn, string lNameIn,int scoreIn[]);
But while calling it on line 39 in your code or line 40 here ...
student[numOfStu].setStudent(id, fName, lName, score[SCORE]);
you are actually passing an integer in place of integer pointer, 4th argument.
You are specifying an index in the array, which passes the integer at that index.
Just pass the array without any index and it should work.
This won't compile because function x is having two overloaded versions with same signature -
void x(char)
It should produce an error "Function Re-Declared" .. something like that.
When the user enters the number wrong 10 times, xxx becomes equal to 0.
And then this code
if (xxx==0) goto son;
causes it to exit. Modify the tekrar function, so that it resets xxx. It asks the user if he would like to play more but doesn't changes xxx variable which causes termination. Or you can manually reset xxx everytime tekrar is called.
Please correct the code tags.
>> operator reads until the first whitespace character. So when you are reading the file which has "burcin eric 783389" with the following code
f>>name1>>numb1;
name1 gets burcin and numb1 gets erec.
Hint : You are adding elements to tree's root only.
And what's the purpose of line 97.
array[index];
Declare find() before main() and it should work.
bool find(int&,int)
cout<<"String";
The "String" should start and end on same line in the editor or you can extend it like ..
cout<<"Str"
<<"ing";
In simple interest, you need to add fixed interest to the sum1 every time in the loop.
sum1=deposit1*interest1/100 + sum1;
In compound interest, you need to calculate interest every time in the loop and add it to the sum.
sum=sum*interest2/100 + sum;
Don't just increment it, you are just adding 1 to the sum1 and sum every time in the loop.
First thing, don't use system("pause").
Why sum1==sum, the question says when the investment of Celio exceeds Daphne's.
Also in loop, you are just incrementing sum1 and sum... do you think that's correct?
Is it that you want the menu to be displayed according to the Account ID?
Can you please detail a little more about your problem.