190 Posted Topics
Re: And you don't need these two lines :) [CODE=cplusplus] #include <cstdio> #include <cstdlib> [/CODE] I wouldn't recommend writing always the same, although it's the easiest way And one thing more. I realise you are just starting in C++, but try not to use [ICODE]system("PAUSE");[/ICODE] Just enter this instead of that: … | |
Re: Several syntax mistakes: 1. Missing opening bracket after main()! 2. Missing opening bracket after for (instead you have closing bracket on line 13.)! 3. Missing closing for-bracket. 4. Missing closing main() bracket! | |
Re: You can read and write almost directly :) | |
Re: It goes like this: n(0) = 1; n(1) = 1; n(2) = n(1), n(2) //so it's actually two numbers n(3) = n(1), n(2), n(3)... Bottom line is: First two numbers just copy. The print others in a for loop | |
Re: [QUOTE=mrrko] I mean... how do I calculate with the size in pounds entered by the user, if it is not used in the function? Thanks a lot for the help!![/QUOTE] Confused :confused: | |
Re: [CODE]while(soldiers.size()==1)[/CODE] This while statement is ill | |
| |
Re: Don't use the same template!!! Especially [ICODE]using namespace std;[/ICODE] And yes, you could use: [ICODE]int main(int argc, char* argc[])[/ICODE] But if you don't need arguments you can use: [ICODE]int main()[/ICODE] | |
Re: Ok, first, the code won't compile without [ICODE]#include <iostream>[/ICODE] As for the shadowing. What have you written is: [CODE=cplusplus] int myfunction(int a_number){ int a_number = 4; //do stuffz return some_num; } [/CODE] See the problem? You are creating a variable a_number at the moment the function starts (in line 1 … | |
Re: It shouldn't happen, but this code isn't giving anything | |
Re: [QUOTE=WaltP;710667]And what does [ICODE]fflush(NULL)[/ICODE] do?[/QUOTE] Flushes everything (like a damn good toilet :) ) | |
Re: Just some literature from wikipedia: "In C99, there is a bool type, along with the values true and false, defined in the <stdbool.h>" | |
Re: It still won't work. You are comparing char with int: getBinary[i] is char, and 1 is int. char != int!!! | |
Re: [QUOTE=ahamed101;710329]Hi, When I used scanf instead of scanf_s, it printed the output properly... I am not aware of scanf_s... googled it and found it out its some secure version of scanf or something... i use unix and this is available only for MS C I guess... [code=c] scanf("%d %d %d … | |
Re: 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 " [CODE=cplusplus] scanf_s("%d %d %d %d", &a1,&a2, &a3, &a4); // not (%d … | |
Re: Post a small code where you are using your function, please | |
Re: You need something like this? [CODE=cplusplus] void Totalinfo( fstream & information, Class& academic) [/CODE] | |
Re: Some changes: [CODE=cplusplus]#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() { … | |
Re: s1 -----S1 s1 is instance of S1. ps -----S1 ps is declared as [ICODE]struct S1 *ps;[/ICODE], but since this is C++, not C it should be: [ICODE]S1 *ps;[/ICODE] (because whenever you make class or struct you make a new object, kind of new variable that goes by the name, not … | |
Re: I believe he's trying to do something like: [CODE=cplusplus] typedef box MyGreatBeautifulBox; //and use it as: MyGreatBeutifulBox<int> a; MyGreatBeutifulBox<char>b; [/CODE] I don't think it can be done | |
Re: 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. | |
Re: 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 … | |
Re: 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: [URL="http://www.cplusplus.com/reference/stl/set/"]http://www.cplusplus.com/reference/stl/set/[/URL] | |
Re: >void Montecarlo(void); >{ What's that semicolon doing there? :) | |
Re: After each [ICODE]cin>>something[/ICODE], add [ICODE]cin.ignore(80, '\n')[/ICODE]; 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 | |
Re: Structure doesn't have restricted acces. You have "myVoltageValues", so simply do: >myVoltageValues.Vcc = 3.14; >myVoltageValues.TblkLoopEnb = 3; >myVoltageValues.Blah = 2.3333333; | |
Re: 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. | |
Re: 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 | |
Re: [QUOTE=ahamed101;702380]Hi Everyone, I know conio.h is not available in Unix. I want to use getch(). Using curses.h needs causes the screen to clear which I don't want. I found a code snippet (source : internet) using termios, it works, the thing is I need to press enter/or any other key … | |
Re: You obviously have three options about kwh, and using if-else is wrong approach. Instead use: [CODE=cplusplus] 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 … | |
Re: The answer is simple: If you are using templates, you can't have header and source code. Everything has to be in one file. | |
Re: How do you expect it to work when you write "complex" into file, and try to get "float" out of it? | |
Re: 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:\\*" | |
Re: 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 … | |
Re: I made slight adjustment: [CODE=cplusplus] sky.erase(sky.begin()+x); [/CODE] More on: [URL="http://www.cplusplus.com/reference/string/string/erase.html"]http://www.cplusplus.com/reference/string/string/erase.html[/URL] EDIT: oh yes, x <= sky.size() is wrong, should be x < sky.size() | |
Re: If you want to pass POINTER to current object, then it is simply [ICODE]this[/ICODE], and not [ICODE]*this[/ICODE] | |
Re: [URL="http://www.cplusplus.com/doc/tutorial/pointers.html"]http://www.cplusplus.com/doc/tutorial/pointers.html[/URL] Check out Dereference operator (*) | |
Re: 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... | |
Re: If he's running turbo C++ v3, I don't think he has headers without .h | |
Re: fflush should not work with input stream! But in some compilers it does! That's all | |
Re: else if{type = 'exit') First, there's some syntax error, but that's different story. type is [B]char variable[/B]. 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) | |
Re: You need two for-loops. First one (outer) should count rows, while inner one should (depending of the row it's in) count columns | |
Re: How's that a programming question? Here: 1 2 3 4 . 6 7 8 . . 1 2 . . . 6 That's uper triangle | |
Re: Sounds interesting. And what kind of help do you need? :) | |
Re: What is this: [CODE]if (genArray[i] == "ACG")[/CODE] genArray[i] == 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 :) | |
Re: Actually, that is a list, not a vector. Minor differences, but still. Here's one way (matrix of strings): [CODE=cplusplus] typedef vector<string> row; vector<row> *vec1 = new vector<row>; [/CODE] |
The End.