- Strength to Increase Rep
- +7
- Strength to Decrease Rep
- -1
- Upvotes Received
- 11
- Posts with Upvotes
- 10
- Upvoting Members
- 8
- Downvotes Received
- 1
- Posts with Downvotes
- 1
- Downvoting Members
- 1
60 Posted Topics
Re: You just want to know how to print a table? I did it using three for loops, kinda like this: [CODE] cout<<"\n"; for(int x=0 ; x<=3; x++){//prints rows of 4 incremented rates cout<<"\trate"; //print one row, then increment the rate }//end for cout<<endl; for(int y = 1; y<=12; y++){//makes 12 … | |
Re: [QUOTE=WaltP;1159755]here we do not not give programs to people,[/QUOTE] Ah, so you [I]do [/I]give programs to people? //just kidding...double negative there, lol | |
Re: Correct me if I am wrong, but it looks to me like what you would like to do is something like this. The inputs are labeled A, B, C, D, and E, respectively. So your first input is the rank of where A is, out of the total amount. So … | |
Is it the boost library? Regex in particular? I have searched and searched, but this is all I could come up with. If this is the correct library, then how do I get it to work in Dev-C++? I managed to add all the boost .h files to my Dev-C++ … | |
Re: The error I get is 'address of while(AreThereMore) will always evaluate to true.' You need the ()'s when calling the function. Also I see a couple of things in your AreThereMore() function: If answer is not true, you need to set it to false. And when you compare you need … | |
Re: It seems to work fine for me, too, though it took me a minute to figure out what the program does. The first number input is the size, right? So if you input 4,3,2,1,0 it will say that the size is 4 and the elements are {3} 2} 1} 0} … | |
Re: My compiler would not let me use sleep (with a small 's'). And...I always use larger numbers. I don't think your delay is very long. If you want a half-second delay: [CODE]Sleep(500);[/CODE] You don't need the tab, if you want the stick to show up in the same spot each … | |
Re: i++; j--; If j==5 and i==0 and we increment i at the same time as we decrement j... after the 1st iteration: i = 1 j = 4 2nd iteration: i = 2 j = 3 3rd iteration: i = 3 j = 2 And your loop doesn't stop until … | |
Re: EOF means end of file. You can check for it like this: [CODE]while(!infile.eof())[/CODE] It looks to me like you have closed your file and then tried to read from it. [CODE]infile.close(); //Force closes the file while (infile) { if([/CODE] | |
Re: I would use [iCODE]string grade;[/iCODE] instead of [iCODE]char grade;[/iCODE], so that you can have the - or + with it. A char represents [I]one [/I]character. Also, why don't you use [iCODE]int main() [/iCODE]instead of [iCODE]void main()[/iCODE] ? And you probably want [iCODE] #include<iostream>[/iCODE] instead of [iCODE]#include<iostream.h>[/iCODE]. | |
My assignment this week deals with using a struct. I think I can do that part. What I'm having trouble with is reading the file into each variable. The first item in the file is text with spaces. The next items are numeric and need to go into other variables, … | |
Re: It is because each line executes in order. The order you have here is to check if f == 5 first, and if so then cout<< your message. If f!=5 though, it will check to see if f==5 once, then go into the loop. There is no code to take … | |
Re: Well, just look where you put the brackets and what is inside them. What does [iCODE]return 0;[/iCODE] do? Do you want that inside your while loop? Also, I noticed before, in your other question, that these brackets don't seem to belong here. And if it was me, I wouldn't indent … | |
I've seen posts here that were posted in the wrong forum. Today there was one in the IT professionals forum that should be posted under HTML instead, and one with C code in the C++ forum. What do you think about creating a forum for members to report posts? Besides … | |
Re: Here is one way of reading from a text file and displaying the contents: [CODE] string sentence; string readSentence; //open file to read ifstream inData; inData.open("YourFileName.txt"); //read first line from the file getline(inData, readSentence); //show error if file not found if(!inData){ cout<< "Can't open input file.\n"; getchar(); } //while there … | |
Re: Not trying to butt in here, but I'd say that the error is on (or at least caused by) a line above the underlined one. A while loop should include brackets like: [CODE]while(condition){//bracket goes here //do stuff }//end loop[/CODE] | |
Re: ...maybe this should be in another forum? | |
Re: You're trying to calculate before you get the input. This line should go after you get the input to assign a value to price and quantity. [CODE]total = price * quantity * tax;[/CODE] | |
Re: some people use [CODE]system("cls");[/CODE] [URL="http://www.daniweb.com/code/snippet216428.html"]Here's[/URL] one example. | |
Re: What does the program do as opposed to what it's supposed to do? Are you getting any errors? Also you should probably use code tags: [code ]paste your code between tags like these, without spaces [/code ]. | |
Re: I do not know how to add new columns to a matrix either. This may not be the exact answer you are looking for, but I think it is similar to what you want to do: [CODE]//if you had a vector called nums, and a 2d array called ary, you … | |
Re: I would make a more general function instead of telling it the exact number of lines. [URL="http://www.cplusplus.com/doc/tutorial/files/"]Here's[/URL] a page with an example of how to check for end of file. | |
Re: You also still have the same 2 issues I mentioned the other day, in your other thread about the 2-d arrays (with this program). While I do not think this will affect your program (because you get the value with user input later) it is still not correct. [CODE] char … | |
Re: In addition to what Fbody said, you have an infinite loop. [CODE]char Y = 'Y'; //add 's around your char printintromessage (); getUserInput (Y); do { if (Y == 'Y' || Y == 'y') { printplayerinfo (numofgamesinseries, numofplayersonteam, i, j); //you'll have an infinite loop unless you stop it somehow … | |
This is my first question here. My latest assignment is to create a random walk program using a 2-d array. The program worked fine until I tried to put this code into a function: [CODE] for(int i = 0; i < 100; i++){ //reset field of flowers for each attempt … | |
Re: Could you use a while loop? Here is an example of a while loop that runs until a condition is met: [CODE]bool x=false; int num = 0; while(!x){//while x is false //test if(num ==5){ //if pass: cout<<"true"; x = true; } else{ //if fail: cout<<num<<endl; num++; } //should exit when … | |
Re: Do you mean that you don't want to have to press enter after each (one character) number is entered? If so, then yes it is possible. I'm sure I have seen this done a different way, but here is one way anyhow: [CODE] char num1, num2, num3, num4, num5; cout … | |
Re: If all your function does is display (print) the name of the shape, then why return anything? I'd just call it a void function and omit the return statement. Then when you call it, don't assign it to anything: [CODE]aFunction(); //call a void function //declare function as void void aFunction(){ … | |
Re: You don't even need to pass in grade or tot_quest into your functions if you are getting their values within the function. You can just define them within the function (if you don't need them anywhere else in the program.) [CODE] double calculateGrade(double grade) { int quest_corr, tot_quest; grade = … | |
Re: I did it like this: [CODE] //separate each digit & place in array nums[0] = number/1000; //first digit nums[1] = (number%1000)/100; //second digit nums[2] = (number%100)/10; //third digit nums[3] = number%10; //fourth digit[/CODE] | |
Forgive me if this is not the correct place to post this question. How do you judge your own programming skills? How do you know you're 'good enough' to land a job in the field and to do a good job? There are so many more questions that I cannot … | |
Re: You can write nested loops like this. Just put a loop inside of a loop: [CODE]for(int x=0 ; x<=10; x++){ //outer loop runs last for(int y=1; y<=10; y++){ //this loop runs second for(int z=0; z<=10;z++){ //inner loop runs 1st }//end for z }//end for y }//end for x[/CODE] | |
Hello everyone. This forum looks like a nice place. I'm glad to be here. I'm currently a Junior in college working toward my bachelor's, which hopefully I'll obtain next Spring. I already have an Associate's degree in Computer Programming. I still have a lot to learn, so I'm hopeful that … | |
Re: I think that they are similar, but IMHO it would be easier to learn one language first, get the basics down, and then concentrate on learning others. In my experience, quite a few of the more popular languages are similar, especially the basic concepts. It's mostly just the syntax that … | |
Re: There are several ways of doing what you want to do here. I'm sure that I have omitted some, but these will work: [CODE] char digit=0; int digit2 =0; cout<<"Enter a digit: "; digit = cin.get(); //assigns whatever (single) character the user enters to variable 'digit' //if they enter more … | |
Re: [CODE] if (ashape = Triangle) { Area = .5 * d1 * d2; return Area; } else if (ashape = Circle) { Area = 3.14 * d2 * d2; return Area; } else if (ashape = Rectangle) { Area = d2 * d3; return Area; } else if (ashape = … | |
Re: Edit: ...it does seem to work when I compile your code, as is. The first line is off, but that's only the formatting (needs to go a bit to the right). However, I do see this: [CODE]int isleapyear; else if (month == 2 && isleapyear) [/CODE] You can't compare an … | |
Re: [QUOTE] BTW it was Queen Elizabeth II who formally declared the USA an independent country. I don't recall when it was but I do remember seeing it on tv.[/QUOTE] Must not have been too long ago, if they had tv at the time. Either that or you (and tv) are … ![]() | |
Re: Maybe your function should return avg instead of sum? | |
Re: I know we're not supposed to give homework help unless the OP shows an effort, but this does look like you've shown an effort. These are the ones that don't look right to me: -- float and double variables should be used: a. To perform monetary calculations. b. As counters. … | |
Re: I would think that your problem is here: [CODE]getline(inData,payto); inData >> payto; inData >> rate;[/CODE] You might have better luck with something like: [CODE]inData >> payto >> rate; // Read in first values, priming read while(inData){ //as long as there are numbers to be read (this loop should get all … | |
Re: I was looking up some things about vectors today. In fact I was actually able to make a program that uses vectors (and actually works correctly!) with the help of two sites: [URL="http://www.cplusplus.com/reference/stl/vector/"]vector [/URL]and [URL="http://en.wikipedia.org/wiki/Vector_(C%2B%2B)"]this one from Wiki[/URL], so maybe this will be helpful to you as well. | |
Re: [QUOTE]I have loads of text boxes (coloured blue) and some buttons. Right now if i click a button it only assigns the frame to textbox1. How do i make it assign to the box that my cursor is on (when i click the box)[/QUOTE] If I read this correctly, what … | |
Re: Well, for one thing, you are asking for (and later printing) 16 inputs from the user, not 15. Also, meaningful variable names (and indenting) would be nice. :) Here's an [URL="http://mathbits.com/MathBits/CompSci/Arrays/Insertion.htm"]insertion sort[/URL] I found interesting, and thought it may be helpful to you. | |
Re: [QUOTE]I need to know why the catch is int i & not int x?[/QUOTE] Because i is the 'name' of the exception thrown, and x is the variable name used to store your input data. You could call your exception e or something else, but it shouldn't be the same … | |
Re: [CODE] void printValues(int numI1, int numI2, float numF1, float numF2) ; int main () { printValues(4, 3, 3.3, 56.6) ; } //test to see it print correctly void printValues(int numI1, int numI2, float numF1, float numF2) { printf("1: %d 2: %d 3: %f 4: %f \n", numI1, numI2, numF1, numF2) … | |
Re: One equal sign assigns a value. Two equal signs compare values. Change [CODE]if(c[i]%2=0)[/CODE] to [CODE]if(c[i]%2==0)[/CODE] and it should get rid of that error. But you probably shouldn't use goto. You can use a[URL="http://www.intap.net/~drw/cpp/cpp04_03.htm"] for loop or a while loop [/URL]or even a [URL="http://mathbits.com/mathbits/compsci/looping/dowhile.htm"]do while loop[/URL] instead. | |
Re: I am not sure about the first part but I can answer the second part. One way to ensure that the input is good (the user enters a number) is to do this: [CODE]void clearError(long int& num){ //pass number in by reference so it can be changed within the function … |
The End.