Holy Necro Bump Batman, make a new thread and I'll see what I can do for you.
Holy Necro Bump Batman, make a new thread and I'll see what I can do for you.
Add Temp=NULL in your constructor.
~ is just the notation for a destructor, you still have to write code GDI.
Right off the bat you can see that there are two problems that will cause you a massive pain. The first problem being you dont have an cout<<endl; anywhere, how are you going to get to the next line? secondly, if you look at the pattern, you can see that the total # increases every two while the total ^ decreases by two. Now you also know that the ^ needs to come twice; before and after the #, so all you need are initial values for ^ and #. So all you need to know for any input(must be odd however) is input-1 and 1. For the first loop output ^ (input-1)/2 once, then # once, the ^ (input-1)/2 again. Go to the next line, subtract 1 from the ^ count and add two to the # count, print them in the same order, rinse, repeat.
Well again there are multiple ways to approach it, one would be "casting" or converting between variable types i.e in to char, but this gets much more complicated when you begin casting two digit numbers and up. Now normally, I would make a check for 0 as an input to prevent it from being used, but if you really insist on including 0, the simple way to do it is use -1 instead of 0. So are you going to ask me what to do if you want to have negative numbers? :p
Your book is quite creative in my opinion, the solution is much more intricate and efficient to be honest.
Im not quite sure if I'm right, but you can't delete those integers because they are static.
Ah, yes you are correct, but the order of the two in my code are interchangeable in the if statements whereas your books snippet explicitly defines them, good catch :).
bleh i get it now, it is saying go make integer r go from the first element of your array to the current element, provided that none of the elements match (*r != *q), r will equal q when the loop breaks. Otherwise, r will be lower than q because of the && *r != *q; portion. *r would be my unique[x] and *q would be input[x]
make another loop to check it and toggle a flag, if it does not pass the check, call your function again, it is only running once; make it recursive!
for (x = sub + 1; x < size; x++)
if(zid[sub] < zid[min])
flag = false;
if(!flag)
sortAr();
Heres a basic snippet
while(exit == false)
flag = true
for(x = 0; x = length-1; x++) //length as in actual length; for a[5] it is 4
if(array[x] < array[x+1]) {
temp = array[x];
array[x] = array[x+1];
array[x+1] = temp;
}
for(x = 0; x < length-1; x++)
if(array[x] < array[x+1])
flag = false;
if(flag == true)
exit = true;
}
well this is quite easy and can be done in multiple ways;
the first is to use a bool array with as many integers as your highest input and toggle it to true if a number occurs, however, this is very inefficient. A better method would be to create another array with the total ammount of inputs you have and set them all to 0. Cycle through your inputs with a for loop and insert every unique number into the second array, checking it each to to see if it already has a number. Then just output your second array and it should be all unique numbers.'
int input[10], unique[10];
bool insert;
for(x = 0; x < 10; x++) {
cin>>input[x]; //input your numbers
unique[x] = 0; //set array to 0
}
for(x = 0; x < 10; x++) {
insert = true; //defaults flag to true
for(y = 0; y < 10; y++)
if(unique[x]==input[x])
insert = false
if(insert)
unique[x] = input[x]; //insert if it is unique
}
//because this array is the same size as the ammount of your inputs, just cout a number if it is not equal to 0, which is your default
for(x = 0; x < 10; x++)
if(unique[x] != 0)
cout<<unique[x];
Silly me, i know something was superflous T.T, good job though!
You never used your sort function ^^;
oh and you need make it recursive because the current function will only make one run, which is insufficient, add another loop to check it and toggle a flag.
Ironically I just wrote a merge sort program for queues a few days back, I'll send it to you tomorrow when I'm at school.
Well thats because you are never going to get 0 unless counter = 0, you have to use the modulus operator(remainder) to determine if it is divisible, look at the code more carefully next time :count / divisor)%2
Well in that case, take your inputs and make a for loop for the ammount of elments you have. Check to see if the presceding element is greater than the next, if it is; switch the two. After you finish this loop, make another loop to check if any element is greater than the next, if it is set a flag to false and exit the loop. Lastly, make an if statement to check if the flag is false, if it is false, call the sort function again. Be sure to set the flag to true at the begning of the function and if done properly, the list will sort it self continually until in correct order, after which the function will have ended.
Sort in which way? Greatest to least, least to greatest? Either way, you can either use sort() included with <algorithm> or create your own recursive sorting function.
Think about it really hard for 10 seconds... If you still can't figure it out,
if((count / divisor)%2 == 0) at least from what I can tell from what you are giving me.
if you had a struct list,
just declare list *F[10];
for each element you would just say F[x]->data to access whatever you need, the only difference from a normal linked list is that you have to address each element when using them(you can use loops too of course).
Eh, I don't wanna give it all for you, what I am saying, is make an if statement to check if the integer is divisible by your divisor first. If it is, accumulate it, if not, move on to the next number. If you don't understand this basic code, I suggest you read up on your books or look through the internet for some guides before coming here.
Well you have your snippet right there >_>, just make an if statement and you are set.
Aren't you the witty one? ;)
the problem is you do not have an accumulator, this revised code should work
int Range (int start, int end, int divisor)
{
int range, counter, sum;
sum=0;
for (counter=start; counter<end; counter++)
{
sum= sum + counter;
}
range = sum / divisor;
return range;
}
note I just changed start to sum, because sum is what you are using to count, sum is what you add to counter, which changes. Before you would only have two digits add each time, wipping the previous result because start is the same and counter changes.
Well there is really nothing stopping you, although it might get confusing to access individual elements at times. Just remeber that you use -> instead of . to access variables in your list(sorry, my example was wrong >_<, but I edited it).
Heh, sorry but I'm about as useful as a hobo when it comes to graphs, as for linked lists, the basic format is:
struct list {
int data;
list *link;
};
basically you create a list *a and link it to another list variable with *link inside list. To create a linked list, you must link the list to each successive chain:
list *one, *head, *p;
int x;
head = one; //records begining of your list
for(x = 0; x < 5; x++) {
cin>>one.data; //takes integer value
p = new struct list; //creates new list
one->link=p; //links current chain to next
one = one->link; //moves from current chain to next
}
one = head; //resets one to begining
In your case, just make data a string and include your doubles as additional variables. All lists are essentially just data and a pointer. You can also make a doubley linked list with a pointer that points to the variable in front of it. I hope this makes sense to you, good luck!
my snippet should do that, it starts with yesno = to y and then asks for a forward or reverse string(your code) after displaying it, it then asks whether or not you want to go again, and then for a forward/reverse string ect, until you enter another character besides 'y'.
Urgh, I skimmed your code and noticed the abscence of string arrays, have you considered using them? They make comparison so much easier. The are declared in this format:
std:: string array[4];
dont forget to include <string>
If you gave me the code snippet of where you think it is wrong, I might be able to look at it more thoroughly, also, have you tried inserting couts and system("PAUSE");s throughout your code to see where it stops?
Whenever I used .txt files they were just on the desktop, but I'd put them in the source folder to be sure. Sorry but I'm not all that experienced.
Change the whiles to if statements, and for all purposes, exitLine is ch so make a while loop around the two statements to ask whether or not the user wants to go again.
char yesno = 'y';
while(yesno == 'y' || yesno == 'Y') {
cout << "Please enter R to reverse the string, and F for a normal string: ";
cin >> ch;
if (ch == 'f' || ch == 'F' ) {
cout << "Type a Phrase: ";
cin.getline(line, 101);
modifytext.PrintF(line);
}
}
if (ch == 'r' || ch == 'R') {
cout << "Type a Phrase Under 100 Characters: ";
cin.getline(line, 101);
modifytext.PrintR(line);
}
}
cout<<"press y to continue or any other key to quit."<<endl;
cin>>yesno;
}
the reason you use ifs is that ch doesn't change from whatever you input earlier so the while loop repeats.
Two things, you do not declare declare sub in the main function, and int size in your void displayAr seems to be superflous. Another thing is in your buildAr function, shouldn't you be using inFile>>num before saying zid[sub] = num ect?
I added two new loops to display the name of the lowest and highest selling products. does this look right? (it worked)
highest = 0; for (int count =0; count < typesOfSalsa ;count++) { if (numOfJarsSold[count]> highest) { highest = numOfJarsSold[count]; } } for (int count =0; count < typesOfSalsa;count++) { if (highest ==numOfJarsSold[count]) { cout<<" The highest selling product is: "<<salsa[count]<<endl; } } lowest = 999//some number you will never exceed with an input for (int count =0; count < typesOfSalsa;count++) { if (numOfJarsSold[count] <lowest) { lowest = numOfJarsSold[count]; } } for (int count =0; count < typesOfSalsa;count++) { if (lowest ==numOfJarsSold[count]) { cout<<" The lowest selling product is: "<<salsa[count]<<endl; } }
I'm not sure what numOfJarsSold[0] is so it could possibly make false positives for certain cases, you can combine the two loops that display the lowest and highest ammount, but it isn't necessary, the code looks a-ok aside from the problem I mentioned earlier.
eh, a really crude way would to make a counter in your loop and system("pause"); after the last cout<< but frankly I haven't figured out why the compiler "skips lines" either yet.
Add a system("PAUSE"); in your display function after the loop.
Looks like lua
Well I didn't really read your code thoroughly so I am going to assume you input the ammount in the order the flavors are listed; in which case, you just cout<<salsa[x] when high = numofjarssold[x].
Well the way I would do it is use a for loop to compare the two arrays and a bool array to track what answers are wrong.
for(x = 0; x < 20; x++)
if(correct[x] != answer[x])
wrong[x]=false;
for(x = 0; x < 20; x++) {
if(!wrong[x]) {
cout<<x<<". wrong"<<endl;
total++;
}
else
cout<<x<<". right"<<endl;
}
cout<<total<<"wrong, "<<(20-total)<<"right"<<endl;
Don't forget to initialise the bool array to true, and you can figure out how to do the percentages by your self quite easily. As for fstream, this link is pretty helpful http://www.cplusplus.com/doc/tutorial/files.html
The easiest way to do this is make a for loop and initialize an integer to 0, everytime a number greater than your integer appears, set it to that number; if not, progress with the loop. At the end you should have to largest integer.
int high = 0;
int x;
int salsa[5];
for(x = 0; x < 5; x++)
if(salsa[x] > high)
high = salsa[x];
cout<<high;
finding the lowest value is not much different, but you can easily figure it out from the snippet I gave you. Hope this helps :)
Its kind of like using a structure(with the inclusion of functions), if you make your class a pointer, use ->.
Sounds like a fun project, it will be much more rewarding if you come up with it on your own :)
The problem being I do not (nor will I ever probally) have admin rights on this computer because my dad forgot the password(GAH), I tried using eclipse C++ IDE but I couldn't figure out how to link it to minGW or cygwin(the guides were for an older version), I also tried to get emacs(failed miserably) so I can't help but have stockholm's syndrome right now with new compilers :/. BUT, there is hope, as I will be getting a laptop in the coming months!
Guess I got the wuss's compiler then, lol.
oh and that would require .h file I made, which would be of little use to atreides because he does not have it >_>(okay so I could have given it to him but thats to much of a hassle)
Heh, I'm probally gonna get hell for this, but the class string is included in <iostream>, using namespace std;(I'm not quite sure which mind you). As for int main(), I'll take your word for(and pretty much all of my observations) because Devc++ does infact allow "default return types," and yes, it does produce a false positive >_<.
I should probally say that I can only partially solve some of these problems as my teacher never really goes into "how" things work, that is to say, my knowledge of the inner workings of c++ are mediocore to say the least. BUT, I do know to solve problems quite well, and I can say with certainty that my palindrome function that uses stacks works perfectly with your case :).
As for commas, you can reverse your string, push it into another string, which adds a comma every three digits after the second, and reverse it again, so a theoretical ammount of $123456.78 would first go to
87.654321
87.654,321
123,456.78
alternatively, because you know there can only be one comma, create an if statement fo find whether or not ammount[2] is used or not; if it is insert a comma through any method of your choosing, if not, then there is no comma at all!
The code required to do this is well within your grasp so I'll leave that to you :) (its amazing how much effort the little things take isn't it?)
Heh, I got confused when you said two inputs, because a palindrome is only one O____O
anyways, this will compile on devc++
#include <iostream>
using namespace std;
main() {
int x, y; //these are your counters
string s1; //string input
bool palindrome = true; //flag for palindrome
cin>>s1;
y = s1.length()-1; //intializes y at the end of string s1
for(x = 0; x < (s1.length()/2-1); x++) { //starts a count from the beginning to half way through s1
if(s1[x] != s1[y]) { //because s1[x] and s2[y] are the same distance from their respective ends, if they are not equal, then s1 is not a palindrome
palindrome = false;
x = s1.length(); //exits loop
}
else
y--; //if the two equal, subtract from y to keep up with x
}
if(palindrome==true)
cout<<"palindrome!";
else
cout<<"not a palindrome";
system("PAUSE");
}
Well you can make a sort function, alternatively you can sort your inputs prior to pushing them into an array with a sort() function included in <algorithm.h>, but I doubt this is what your professor wants you to do. I suggest using a recursive function for sorting.
oh and although I'm not quite familiar with visual studio 2008, mabe you should have #include "LinkedListType.h" depending on how you saved your header file.
Although dragon is right about palindromes; you do not need to go as far as creating a third string; you can use a while or for loop to compare the the strings simulataneously and return false the moment a pair of characters differ.
i.e.
int x, y;
string s1,s2;
bool palindrome = true;
cin>>s1>>s2;
if(s1.length() ==s2.length()) {
y = s2.length()-1;
for(x = 0; x < (s1.length()/2-1); x++) {
if(s1[x] != s2[y]) {
palindrome = false;
x = s1.length();
}
else
y--;
}
if(palindrome)
cout<<"palindrome!";
else
cout<<"not a palindrome";
Have you considered using a switch or while loop? After all, you only need to go through each element once right?
Well there are a multitude of ways you can approach this; one being setting a flag for each vowel to disregard it after it has been used(tedious/crude) alternatively you can make a structure of a int and character(probally not what you are looking towards). So what do you do? Well you its simple really, you have already sorted your vowels from highest to lowest, so you dont even need an those encompassing if statements!
for (int z=0; z<5; z++){
if (v[z]==a){
cout<<"There are "<<v[z]<<" instances of the vowel A";
cout<<endl;
continue;
}
if (v[z]==e){
cout<<"There are "<<v[z]<<" instances of the vowel E";
cout<<endl;
continue;
}
if (v[z]==i){
cout<<"There are "<<v[z]<<" instances of the vowel I";
cout<<endl;
continue;
}
if (v[z]==o){
cout<<"There are "<<v[z]<<" instances of the vowel O";
cout<<endl;
continue;
}
if (v[z]==u){
cout<<"There are "<<v[z]<<" instances of the vowel U";
cout<<endl;
continue;
}
}
should suffice(provided you do not have to output a different things for special cases i.e. "there are zero 'A's")
Hmmm, you two are looking far too deeply, there is really no need for a do while at all. You only need three if statements at most(check x, check y, check flag) and four for loops for the array creation portion. But if you are really interested in programming, I suggest looking into a recursive function, rather than resetting count each time. An example would be like
void inc(int x, int y) {
x ++;
if(x < y)
inc(x,y);
}
This example, although crude, gives the basic gist of a recrusive function; it repeatedly calls itself until the parameters are met. If you two are ambitions; try using a recursive function to create your unique grid. Other than that, you two seem to be on the right rack, but remeber to tag && k != j and && j != i to your two if statments respectively. In each of the two cases grid[j] is the exact same thing as grid[k][j] because i is equal to k. I hope this helps, don't give up!
Er nevermind, couldn't see that last bracket.
The beauty about stacks is that you can use them in so many ways to solve one problem; the simplest, would be to read a string in a loop and insert every '(' into a stack, while popping the stack once for every ')'. Under this logic, simply make the statement false if the stack is empty when you attempt to pop it, or if you still have a value in your stack when the statement ends.