Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I need to throw std::exeption if rad is negetive number, how can I throw?
void Circle::setRad(double rad) {
if (rad < 0)
{
throw(std::exception );
}
radius = rad;
}
Usually you should throw one of the derived classes:
throw std::invalid_argument("radius must be nonnegative");
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm new to C++ and I don't understand why I'm getting a not declared error on this:
int main(){
string listOfColors[5] = {"red","blue","green","yellow","magenta"};
for(int i = 0;i < sizeof listofColors;i++){
cout << listofColors[i] << "\n";
}
return 0;
}
This is my first utilization of an array so far, so I may just not be declaring it correctly. I also had the array declaration before the main function beforehand.
You declared your variable as listOfColors (capital "O"), and then you use it as listofColors in your for loop. All you need to do is to capitalize the "O" when using your variable.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I'm writing a method that accepts the value of amount to be deposited, as a parameter. If the amount is greater than bal (balance) the account will be updated with the new amount. Otherwise it returns the old bal and exits. Here is my code:
double withdraw(double amount)
{
if((bal-amount)<0)
{
throw new Exception
("There were insufficient funds");
else
bal=bal-amount;
return bal;
}
}
I'm having errors with the Exception and the else statement.
You have placed the { } in the wrong place.
double withdraw(double amount)
{
if((bal-amount)<0)
{
throw new Exception("There were insufficient funds");
}
else
{
bal=bal-amount;
}
return bal;
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
In the following piece of code I get the error mentioned below. Please tell me
Why *p=t gives error here
void reverse (char *p)
{
int length=strlen (p);
int c=0, i=length/2;
char *Temp=p+length-1, t;
while (c<length)
{
t=*Temp;
*Temp=*p
*p=t;
//Gives error as illegal, right operand has type char*
//Why is the error in the above line?
c++;
Temp--;
}
}
There is a semi-colon missing:
t=*Temp;
*Temp=*p ; //--here
*p=t;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm new to templates and couldn't find the answer to my problem on the forums here, maybe I just don't know what to search for exactly.
My code:
template<class T>
vector<T> properDivisors(T input) {
vector<T>retVal;
for(T d = T()+1;d<input;d++) {
if((double)input/(double)d == input/d)
retVal.push_back(d);
}
return retVal;
}
template<class T>
T sumTypeOf(T input) {
vector<T>divisors = properDivisors(T);
return someEnum;
}
When compiling I get an error on the line:
vector<T>divisors = properDivisors(T);
The error is:
error: expected primary-expression before ')' token
You need to pass a value, not a type:
vector<T> divisors = properDivisors(input);
// ^^^^^
Hah! Sorry everyone, the problem was that I should have written properDivisors(input)
Stupid nub error... sorry...
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
why doesn't this compile:
enum E { a, b}
typedef struct { int i; E e; } S;
int main(){return 0;}
I get different errors on different system.
You need a semicolon after the enum.
enum E { a, b};
There is no semicolon after the enum.
no semi colon at the end of enum
The enum needs an ; after its }