181 Posted Topics
Re: So, you if else satements: [CODE] if (r<=3){ return 100; }else if (r<=6); return 80; else if (r<=9); return 60; else if (r<=12); return 40; else if (r<=15); return 20; else return 0; [/CODE] if you have more than one statement in any if/ if else statement, you must enclose … | |
Re: [CODE] void initialize() { input.open ("WUexamp1.txt"); } [/CODE] Files should not be opened this way. You should pass the file name and the fstream object as reference. Like this: [CODE=c++] char fileName[] = "input.txt"; bool initialize(char[] fName, fstream& iFile) { iFile(fName, ios::input | ios::beg); if (iFile.fail()) return false; // Indicates … | |
Re: Ok, first off, please read this before posting code again: [url]http://www.daniweb.com/forums/misc-explaincode.html[/url] Second, you need to accumulate the numbers that are entered by the user. Depending on what you have learned so far, you can either use an accumulator (the numbers entered by the user are added to this variable with … | |
Re: When you pass an array to a function, you only need to pass the name of the array (i.e starting address) Do not include size declarations [CODE=c++] pickColor(color[3][19], red, green, blue); // WRONG! pickColor(color, red, green, blue); // Correct [/CODE] | |
Re: TBH, I cant read your code.... You used code tags but no indentation..... people are MUCH more likely to help if your formatting is good.... or even readable | |
Re: [QUOTE=phpangel;1109970]well if u posted the answer and i ddnt understand does that means i'm nt C++ programmer, anyway if u ready 2 explain whatz the right answer then appreciate it.......if not thanx for ur advices and good bye[/QUOTE] Sorry to add to this already out of control fire BUT it … | |
Re: Kind of a crazy idea but what if you write all of the ints/ doubles to a txt/ binary file then read them back in as chars? | |
Re: Your code looks like this: [CODE] for (int i = 0; i < sum_number; i++) { cout << "I cant read this code!!\n"; } [/CODE] Code should look like: [CODE=c++] for (int i = 0; i < sum_number; i++) { cout << "I can read this code!!\n"; } [/CODE] Oh … | |
Re: [QUOTE=blueman:-0;1112611]how i can do database in c++[/QUOTE] Ok, well first, I would read the rules on Posting in the forums because this is not a good question. This forum is for helping people out with the areas of C++ that they are having trouble with, your question is too broad. … | |
Re: [QUOTE=firstPerson;1112791]I'll give it to you for 1 zillion gazillion quintillion dollars?[/QUOTE] Ill do it for half that =) Im cheap heheh | |
Re: Yea, looking at your code makes my brain hurt. A) Please read the forum rules on Code tags and.... B) You need to work on your style | |
Re: Just an idea.... im not sure if this is what you want but, you could create a struct that contains the chemical name and chemical makeup, then create an array of that struct to store file contents, which is easy. But in order to list in ascending order you HAVE … | |
Re: [QUOTE=Intel;93471]Man you've done most of the work, just call your function in main, here is the code with some changes: [code] #include <iostream> #include <iomanip> const float PI= 3.14; float circle_area(float &radius); float circle_area(float &radius) { using namespace std; float area= PI*radius*radius; cout<< "The area of the circle with radius … | |
Re: [QUOTE=Salem;1109733]> (I loop it 250 times) ... > srand(unsigned(time(NULL))); Unless your code also takes 250 seconds to run, then srand() is always going to be seeded with the SAME value, and rand() is always going to return the SAME value(s) as a result. srand() needs to be called ONCE only, … | |
Re: I agree with jonsca, use a 2D array. The rest is all up to you and VERY customizable. Depending on how crazy your prof is.... you could step through the array and randomize each dice using rand() generator limited by the amount of letters in alphabet. | |
Re: You do need a second for loop (one for the rows, one for the columns, in the array) It may be easier to use pointers: [CODE] int* return_ptr(int str[][20], int x, int max_rows, int max_col) { int* a_ptr = new int; for (int i = 0; i < max_rows; i++) … | |
Re: [QUOTE]combining tutorials never works for a newbie to C++[/QUOTE] Newbie to C++ trying to use WinAPI is going to result in a lot of headaches and errors. I agree with sticking to a console app. | |
Re: Another good way of doing it (without use eof() ) is: [CODE] while (myFile.getline(line, '\n')) cout << line << endl; [/CODE] | |
Re: [QUOTE=zulqadar;1107842]i am going to make the Database (i.e enter name, phone # etc) but how i will make it permanent (i.e to save it permanent). When i close the program and reopen, my previous Data that i had enter should Present??? How i will make it???[/QUOTE] [QUOTE=WaltP;1107846]Write to a file.[/QUOTE] … | |
Re: [QUOTE=keeperx;1108294]We first of all, I said im writing MY first c++ program, that does not mean that haven't been playing around with other code for a while. Secondly info about the mud can be found at lithmeria.com (still beta) and your sarcasm is unappreciated. Thirdly im not throwing around terms … | |
Re: Also rkulp, please search the forums for already made topics that include your problem before posting a new instance of it. Click here: [url]http://www.daniweb.com/forums/thread253567.html[/url] | |
Re: Hey, welcome to the forums. Typically this forum is used for learning/ correcting purposes even on the more advanced stuff (which is in the 'Please read before posting' section of the forum rules) which means that forum members are not typically going to do the work for you. Instead, post … | |
Re: Check out this snippet you have: [CODE] //Get the user to enter a sentence cout<<" Please enter a sentence.\n"; cin>> Phrase; cout<<" The number of words in your phrase is " <<Phrase.length()<<".\n"; [/CODE] If you are ONLY looking for words, not the entire string length, then Phrase.length() won't work because … | |
Re: I dunno if you read this already but this is probably one of the better explanations ive seen [url]http://compprog.wordpress.com/2007/11/20/the-fractional-knapsack-problem/[/url] | |
Re: [CODE] char input[8]; cout<<"input: "; cin>>input; for(x=7;x!=0,x--) { cout<<input[x]; } [/CODE] The above will work but it is limited becauseyou don't really know how large of a string the user will enter. Instead use this: [CODE] const int MAX_STR = 20; // Obv can be any number char input[MAX_STR]; cout<<"input: … | |
Re: [CODE] cin >> var1 >> var2 >> var3 >> var4; [/CODE] cin will ignore the whitespaces and newlines and input to multiple variables *EDIT: I noticed I didn't really offer a true solution because you dont know how many commands the user will enter so you could do this: [CODE] … | |
Re: I agree with Dave, depending on what you've learned so far, accept all input as a string and use atoi and atof string functions to convert them (So your prog wont freak out if letters are entered into an int or double variable) | |
Re: Also, a smal logical problem : [CODE] int searchList(const int list[], int size, int value) { int index = 0, position = -1; bool found = false; while(index < size && !found) { if(list[index] == value) { found = true; position = index; } index++; } return position; } [/CODE] … | |
Re: Looking at the for loop in your backwards function: [CODE]for(count = SIZE; count >= 0; count--); { cout << strPtr[count] << endl; }[/CODE] The first thing you print is strPtr[11] which will contain logical garbage, the array will only go to subscript [10] if the array size is 11. Instead, … | |
Re: I dont know if Im totally blind (which is an option) but what problems are you having with the code. I was going to read through it and see if I could spot something but its easier if I know whats wrong.... guess I could also compile/ run it too … |
The End.