75 Posted Topics
Re: cout << Accelerate(first) << endl; The cout implies that you want to output something using the function, Accelerate. The function Accelerate, when you called it Accelerate(first), does not take any parameters in the declared or defined function. Nor does it imply outputting any data either. [CODE] void Car::Accelerate(){ Speed = … | |
Re: Because you are passing a char to a int variable. | |
Re: [CODE] #include <iostream> #include <string> using namespace std; void daysOfChristmas (int days, char switcher, string b[12]){ (days > 0 && switcher == 'y') ? daysOfChristmas(days - 1, 'y', b): false; if (days > 0) { daysOfChristmas(days - 1, 'n', b); cout << "on the " << days << " day … | |
Re: I copied and pasted what you had. The only solution I came up after compiling with no errors is: #include<vector> in the header file Oh, and get rid of std:: in std::vector<int> v1; So its just vector<int> v1; | |
Re: First, do what jonsca suggested by creating a new variable, adding to the variable of the current grade to get a running total of all grades added together, then divide by NUM_SCORES (sum)/NUM_SCORES will give you your average. To extend on that, you will need to add an additional for-loop … | |
Re: OH I see check your IF STATEMENT.. GET RID OF THE ; if(begllts <= intarray[m] && intarray[m] <= endllts); //<--- that last ;, Get rid of it BAD, NEWBIE BAD .. :D | |
Re: You don't need to have the data type when calling your function in the main() function. [CODE] int main() { //called functions userData(string studentName, int numOfClasses, char letterGrade); calData(int totalPoints, int numOfClasses); displayData(string studentName,char letterGrade, double gpa); getch(); return 0; } [/CODE] You also need to initialize totalPoints to zero … | |
Re: You also may want to make functions for each of the cases. [CODE] case '1': first_function(Parameter_list); break; case '2': second_function(Parameter_list); break; default: break; } void first_function(Parameter_list){ <code> } void second_function(Parameter_list){ <code> } [/CODE] makes it cleaner, you can also use this code outside of the switch statement. | |
Re: call the function multiple times. If you are reading the input from a file, you can run a while loop that checks for EOF. If you are reading from user input, make a sentinel to end the while loop. while(string_name != "Done"){ // or change the string to whatever you … | |
Re: The nested for loop is what you are looking for. You will use nested for loops once you get into array of arrays. [CODE] void buildSquare( int length, char symbol){ // Length = Length x Length to make the box // Symbol will be used to make the box // … | |
Re: As Nandomo suggested, you need to use strncpy. You are using the char arrays as C strings, and as such, they use a different method than normal char arrays, or even strings. It would be easier if you just changed all the types (chars) to string. So you'd have [CODE] … | |
Re: Good luck trying to contact Mr. Bill for that answer. I suggest googling it. As I just did, [url]http://www.makeuseof.com/tag/5-ways-to-make-your-own-screensavers-windows/[/url] Question? How is this related to C++? If you have any program that you would like use to look at, I know I would be interested in seeing any progress you've … | |
Re: This is what I ended up writing. [CODE] #include <cstdlib> #include <iostream> using namespace std; void compare(int problem[], int SIZE); int main(){ . . . . /* I placed this following section at the very end of your program, between the last else statement and your system pause. */ int … | |
Re: Glad you got the answer :D I would suggest you use the following whenever you use a file for data. It may help with an immediate solution that would otherwise be directly hidden from you. [CODE] ifstream fin; fin.open ("1.txt"); if(fin.fail() ){ cout << "Input file failed to open.\n"; exit(1); … | |
Re: You also may want to read up on strings and string input, from what I read from multiple other sources, you want to be using the standalone function getline(cin, npcname) vs the regular cin >> input. Mixing cin >> with strings may give some funky results. | |
Re: This is what I ended up coming up with. First you want to make sure you can open your file. If you cannot open your file, your arrays will automatically be filled with junk. That may be half of your problem. After that, I just used cout << as a … | |
Re: This is what I came up with. The code works for any valid input from 1 - 9. You can change the range from a number higher than 9 or lower than 1. [CODE] #include<iostream> using namespace std; int main(){ int number; cout << "Please input a number 1 - … | |
Re: Seem like your coding structure is a little off, perhaps something like this? This is just a snippet of what I just wrote, but I did write the entire program to make sure the snippets work properly. The output seems correct with the desired input in the array. I won't … | |
Re: The question is why you would want to know the exact location of variable char a. It's useless as when the variable is initialized with the onset of the program, the variable will be in a different memory location. Hence, hard coding memory locations will be meaningless. [CODE] #include<iostream> using … ![]() | |
Re: Can you paste the code that you have written so far? | |
Re: I just started back into C++ from taking some time off from it as well, slight rusty, but let's see if I can give you a shot at what you are asking for. class FullOfFunctions{ public: void function(int happy_num); //pass by value void function2(int & happy_num); //pass by reference private: … | |
Re: Instead of having the user input a statement, have the program ask a question and the user reply with yes or no. At which point, if the answer is yes, you lead down one road of possibilities to what the answer is. Otherwise, head the other direction. Having the user … ![]() | |
Re: #include <string> You can assign value by, int main() { string name; name = "This is a string. Don't forget to use double quotes instead of single!"; cout << name; Output: This is a string. Don't forget to use double quotes instead of single! This string class has a lot … | |
Re: Just a quick note. What you had earlier, char name; is the same as char name[1]; // variable holding 1 character // They changed it to 30, char name[30]; // so that any input you enter will have enough space to be saved to the variable "name". |
The End.