error message with this line [closed] - c++

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
Why do i get this error message?
Error: expected a ';'
from:
int main()
{
int score;
double distance;
char playAgain;
bool shieldsUp;
short lives;
short aliensKilled;
score = 0
distance = 1200.76;
playAgain = 'y';
shieldsUp = true;
lives = 3
aliensKilled = 10;
the error is under distance = 1200.76; and aliensKilled = 10;,

You have:
score = 0
You want:
score = 0;
Similar for lives = 3

You really forgot something:
...
score = 0;
...
lives = 3;
...

Related

C++ code: count not working [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I wanted to ask, i formulated this code to solve a question, but count does not seem to provide the right value.
Any advice.Any help appreciated. Thanks.
#include<iostream.h>
#include<conio.h>
void main()
{
int count;
for(int a=1;a<125;a++)
for(int m=1;m<125;m++)
for(int n=1;n<125;n++)
{
if(a*(m+n+2)==249-m)
{
cout<<"a = "<<a<<" m = "<<m<<" n = "<<n<<"\n";
count=count+1;
}
}
cout<<"count = "<<count<<"\n";
getch();
}
You do not init the count. Remember to set int count = 0;.
Your compiler will warn you about this and save you the trouble of debugging or asking if you only let it. (from #chris)

how to make these testcases code nice? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am a freshman of TDD and C++, I write some code works but it seems ugly...
could you give me some tips on how to refactor these code?
I define testcases like this:
// define some test case
namespace test_case_planes {
const std::string t_filename = "planes.segy_first_trace";
boost::uintmax_t t_file_size = 5888;
boost::uintmax_t t_traces_size = 1;
boost::int16_t t_trace_samples_size = 512;
boost::int16_t t_sample_interval = 4000; // 2000us, 2ms
}
namespace test_case_ld0042_file_00018 {
const std::string t_filename = "ld0042_file_00018.sgy_first_trace";
boost::uintmax_t t_file_size = 12040;
boost::uintmax_t t_traces_size = 1;
boost::int16_t t_trace_samples_size = 2050;
boost::int16_t t_sample_interval = 2000; // 2000us, 2ms
}
and test like this(with google test)
TEST(Segy, constructWithNoParas){
using namespace test_case_planes;
segy::Segy* test_segy = new segy::Segy();
EXPECT_EQ(test_segy->getFilename(), t_filename);
}
TEST(Segy, constructWithFilename){
using namespace test_case_ld0042_file_00018;
segy::Segy* test_segy = new segy::Segy(t_filename);
EXPECT_EQ(test_segy->getFilename(), t_filename);
}
TEST(Segy, setFilename){
using namespace test_case_ld0042_file_00018;
segy::Segy* test_segy = new segy::Segy();
test_segy->setFilename(t_filename);
EXPECT_EQ(test_segy->getFilename(), t_filename);
}
I think what you are looking for is a fixture. I am not familiar with google test, but test fixtures should be available in most test frameworks. You should look into the documentation for that.

replace function in std::string giving problems in C++ [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am using C++ string functions in cocos2dx. I have the following string CorrectAns = "below".
for(int i = 0; i<CorrectAns.size();i++)
{
CorrectAns.replace(i,i,"?");
}
This function should return my string as "?????", but its returning only 4 charcters ie "????".
When I write like this,
for(int i = 0; i<CorrectAns.size();i++)
{
if(i == 0)
{
CorrectAns.replace(i,i,"?");
}
}
It just crashes.
and works fine only when I write it as " CorrectAns.replace(i,i+1,"?");"
Why is the function working this way?? Can anyone help me please??
string& replace ( size_t pos1, size_t n1, const string& str );
For the versions with parameters pos1 and n1, the section replaced
begins at character position pos1 and spans for n1 characters within
the string.
So you should use
for(int i = 0; i<CorrectAns.size();i++)
{
CorrectAns.replace(i,1,"?");
}
Mb it will be more usefull use something like
CorrectAns.assign(CorrectAns.size(), '?');

What is the check_union256d? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
What is the check_union256d function?
It's placed in following code:
/* { dg-do run } */
/* { dg-require-effective-target avx } */
/* { dg-options "-O2 -mavx" } */
#include "avx-check.h"
void static
avx_test (void)
{
int i;
union256d u, s1, s2;
double e [4];
s1.x = _mm256_set_pd (2134.3343,1234.635654,453.345635,54646.464356);
s2.x = _mm256_set_pd (41124.234,2344.2354,8653.65635,856.43576);
u.x = _mm256_div_pd (s1.x, s2.x);
for (i = 0; i < 4; i++)
e[i] = s1.a[i] / s2.a[i];
if (check_union256d (u, e))
abort ();
}
It's from Intel AVX which is:
a new 256 bit instruction set extension to SSE and is designed for applications that are Floating Point (FP) intensive.

function keeps returning NaN [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
Hi guys i know what NaN(let me say i know the acronym stands for Not a Number) is but i don't understand why C++ returns it - The following is the approximation of the mathematical constant e - When using the debugger the functions evaluate fine, it's when writing to the console that it returns NaN
Thanks for any feedback
double Factorial(int k)
{
if(k == 0)
return 1;
int value = 1;
for(int i = k; i > 0; i--)
value *= k;
return value;
}
double e(int p)
{
double value = 0.0;
for(int i = 0; i < p; i++)
{
value += 1/Factorial(i);
}
}
You don't return a value in your e function.
You forgot to return value at the end of e. I don't know when c++ stopped warning about missing returns.