Zip and post entire code, please.
It's frustrating me now too :)
chunalt787 commented: thanks for trying to help +1
Sci@phy 97 Posting Whiz in Training
Zip and post entire code, please.
It's frustrating me now too :)
First: this is not C++ program!
Second: scanf_s - what kind of function is that? I don't know, maybe it exists, but I've heard only of scanf.
Third: solution is simple, remove blank space between last %d and "
scanf_s("%d %d %d %d", &a1,&a2, &a3, &a4);
// not (%d "), but (%d")
Fourth: Don't write void main()
! Write int main()
instead.
Well the definition is within the class and classes can access their own private data members so ya it should work. I tried putting it in the public section just to check and it did the same thing. As to your example thats basically the same thing that im trying to do. I don't see why mine doesnt work.
I'm not sure about this.
Function can access IT'S own members (this->memb1; this->memb2;)
But I'm really not sure about accessing other instance of same type...
Maybe your problem is in something else...
I am not sure about this , But Why returning (*this)? In your = operator.
(*this) is returned so you can write things like:
myObjA = myObjB = myObjC;
Are you sure this code works:
ll = queue.ll;
'll' is under private section, right? I'm not sure if you can access it.
Here's my code example if it helps:
//operators
//=
Complex& Complex::operator=(Complex const& aCplx){
if (this != &aCplx){
mNum.Im = aCplx.getIm();
mNum.Re = aCplx.getRe();
}
return *this;
}
You can read and write almost directly :)
Some changes:
#include <iostream>
using namespace std;
const int MAX = 5, MAX2 = 3;
class notebook {
int num;
public :
notebook (); //this is wrong. Either write some constructor or don't write it (use default)
void set_num( int n ) { num = n; }
int get_num() { return num; }
};
int main()
{
notebook Num_Of_Notebook[ MAX ][ MAX2 ] = {};
int unitNumber = 0;
for (int i = 0; i < MAX; i++) //missing bracket!
cout << "Notebook Model " << i + 1;
for (int j = 0; j < MAX2; j++) {
cout << "Branch " << j + 1;
Num_Of_Notebook[ i ][ j ].set_num( unitNumber ); }
cin.get();
cin.ignore();
return 0;
}
It still won't work. You are comparing char with int:
getBinary is char, and 1 is int.
char != int!!!
I believe he's trying to do something like:
typedef box MyGreatBeautifulBox;
//and use it as:
MyGreatBeutifulBox<int> a;
MyGreatBeutifulBox<char>b;
I don't think it can be done
s1 -----S1
s1 is instance of S1.
ps -----S1
ps is declared as struct S1 *ps;
, but since this is C++, not C it should be: S1 *ps;
(because whenever you make class or struct you make a new object, kind of new variable that goes by the name, not by "struct name")
But back on question, well, try to guess it?
S1 *ps;
Yes, it's a pointer that points to S1 type.
as -----S1
as is declared as S1 as[] = ...
So as is array of S1's (same as int as[] = {1, 2, 3, 4})
s1.c ---char
Pretty close, but not. Variable c inside s1 (and remember, s1 is an instance of S1!) is char c[4];
So s1.c is array of chars. It's size is 4 chars.
s1.s ---char
Same again. s1.s is pointer to type char.
s2.j ---int
That's right!
s2.ss --S1
Correct again.
*ps->s ----?
Ok, this is sort of nice. The better (more readable) syntax is: *(ps->s)
So, what is "ps->s"? It's the same as (*ps).s so entire line is equivalent to: *( (*ps).s );
Figure out what that is ;)
But this seems like some homework assignment... And I just solved it to you :(
You cannot use fact as an loop iterator and as your final variable!
Try to see how the program is going to run for x = 3, for example.
If you put some struct inside class, then it is defined only inside that class!
The difference is between declaring another datatype, and declaring another instance!
If you declare datatype inside class, it's not available outside of that class!
If you declare datatype outside class, it's available inside and outside of class!
But creating instaces of that datatype is another story...
>void Montecarlo(void);
>{
What's that semicolon doing there? :)
It's best that you don't use array, but binary tree to store info (fastest way to search if you have a lot of numbers stored).
Check this out:
http://www.cplusplus.com/reference/stl/set/
Structure doesn't have restricted acces. You have "myVoltageValues", so simply do:
>myVoltageValues.Vcc = 3.14;
>myVoltageValues.TblkLoopEnb = 3;
>myVoltageValues.Blah = 2.3333333;
Learn syntax of while loop!
That's because of my other post. You don't do nothing with string that you pass to that function.
And there is a problem is getInputByscanf() function!
HINT: you can't assing string (%s) to char!
What is char input[]
for?
Ok, what were you trying acomplish with this:
>printf("%s", getInputByscanf);
First, that getInput... is function, so you have to call it with "()" brackets.
But still, it's nonesence
You obviously have three options about kwh, and using if-else is wrong approach.
Instead use:
if (kwh <= 20){
//do some coding here
}
else if (kwh > 20 && kwh <= 40){
//do other code here
//notice that I wrote here kwh > 20, not kwh >= 20
//that's because kwh == 20 is included already
}
else{
//some code here if it's not in first two
//(so it's obviously kwh > 40)
}
The answer is simple:
If you are using templates, you can't have header and source code. Everything has to be in one file.
It isn't strictly related to namespaces.
If you write a function outside of class it belongs, you have to use :: operator!
Otherwise, compiler won't know if it's some other function or that particular one.
How do you expect it to work when you write "complex" into file, and try to get "float" out of it?
I'm not sure about the code itself, but the problem can be as simple as:
'\' is sort of escape key inside string ("\n", "\t", "\a"...)
If you want to really type '\', you have to write: "\\".
So, instead "C:\*", try "C:\\*"
After each cin>>something
, add cin.ignore(80, '\n')
;
That's because "cin>>" takes what he needs (in your case character) but leaves everything else including newline char, so you have to get rid of it
I made slight adjustment:
sky.erase(sky.begin()+x);
More on: http://www.cplusplus.com/reference/string/string/erase.html
EDIT: oh yes, x <= sky.size() is wrong, should be x < sky.size()
First: I believe you know what functions are? Or at least you should. Well, recursion is when you call some function inside itself.
This is not a recursion!
Second: If you want to make a simple menu (like that what you said, y to enter another, n to exit) you have to encapsulate most of your code (best would be to make a function) and put it in while loop, something like this:
char decision;
int flag = TRUE;
while (flag){
/*do some stuff here*/
printf ("Do you want to continue (y/n)\n");
scanf("%c", &decision);
/*be careful, \n stays in input buffer*/
if (decision == 'y') flag = TRUE;
else flag = FALSE;
}
Have you read your errors?
No 1: invalid preprocessing directive #incluce
Have you heard of INCLUCE? I haven't
No 2: expected nested-name-specifier before "namespce"
Have you heard of NAMESPCE? I haven't
No 3: namespce again, and so on...
Never test end of file with .eof()!!! It's wrong.
Instead, replace !indata.eof()
with (indata>>info)
(and of course, remove same line after while)
Without multithreading, I don't believe that can be done.
Oh, nevermind that.
I have to add that because my command prompt would close immediately after the execution of program (so I wouldn't be able to see what the program has printed out)
Simplyfied, there is some "GODlike" program that starts your C++ code:
int a = main();
//do stuff with a
If you write "void main()" variable a will be garbage.
MOST of the time, it doesn't matter, but it's better not to go against GODlike program :)
More info on:
http://www.gidnetwork.com/b-66.html
Ok, and you have just one slight error that programmers freak about. Instead of writing void main()
, consider using int main()
.
Write a function:
std::ostream& operator<<(std::ostream& os, Item const& It);
And declare it as a friend of class.
Inside function you need to choose what to print.
For example:
os << some_class_variable << some_other_class_variable;
or similar.
And try to google it out, you have lots of examples of overloading <<
You need to overload operator <<.
The problem isn't in pointers, they work fine.
But when you write: cout << *items[i]
it's like you wrote:
Item a(19);
cout<<a;
And that isn't defined
//start printing numbers
for (i = starting_num; i <= ending_num; i++){
cout<<i;
cout<<" " //this prints separation between two numbers
}
Yes it does :)
Ok, I made two adjustments: first, since i don't know what Item is I typedef'ed it.
And second, you for loop won't print items[9], so I changed that too:
#include <iostream>
using namespace std;
int main()
{
typedef int Item;
Item* items[10];
items[0] = new Item(5);
items[1] = new Item(3);
items[2] = new Item(4);
items[3] = new Item(9);
items[4] = new Item(2);
items[5] = new Item(0);
items[6] = new Item(6);
items[7] = new Item(1);
items[8] = new Item(8);
items[9] = new Item(7);
int i;
for (i=0;i<10;i++)
cout << *items[i]<<endl;
cin.get();
return 0;
}
So, as williamhemsworth says, the problem is probably inside Item class
Separate printout to the screen in:
dots before numbers and number.
So, first, if you are in row 0 (first one) the dots should be invert from that (like some_value - nr_of_row), so if you go down the dots should decrease (some_value you have to figure out yourself).
And after dots just print numbers with some_other_value space after them
You need two for-loops.
First one (outer) should count rows, while inner one should (depending of the row it's in) count columns
I'd appreciate some more code
How do you assing memory to each pointer?
How's that a programming question?
Here:
1 2 3 4
. 6 7 8
. . 1 2
. . . 6
That's uper triangle
From http://www.codersource.net/cpp_tutorial_this_pointer.html
this pointers are not modifiable.
So I wouldn't recommend that :)
If you want to pass POINTER to current object, then it is simply this
, and not *this
It has already been pointed out to you.
if (genArray[i] == "ACG")
This will not work, your are comparing a char* with a string. As it has already been pointed out.I'll just restate the fact you need to check character by character
if (genArray[i] == "A"){ if (genArray[i+1] == "C"){ if (genArray[i+2] == "G"){ std::cout << "Found 1!" } } }
very simple way
And of course, to write 'A', 'C', 'G', not "A", "C", "G"
What is this:
if (genArray[i] == "ACG")
genArray == some_character, not some_string!
The code isn't that simple... You have to check char by char if 'A' then 'C' then 'G' occurs!
And of course, typos that Salem told you :)
As I understood, it's very simple game. It may even not be treated as a real "game".
There's a matrix of cells, and cells can be live or dead. You set up a matrix (decide which cell is live and which one is dead) and then you start the game.
Then you have nothing more to do. Game has 4 simple rules about creating new cells, destroying old ones, and by that a matrix changes all the time, and you can watch :)
Sounds interesting. And what kind of help do you need? :)
else if{type = 'exit')
First, there's some syntax error, but that's different story.
type is char variable. How can it store 'exit'? Besides, what is 'exit'? (answer: nothing)
Try to change it like, if user types 'x', or 'e'... or simply else (not 1 or 2)