ndeniche 402 Posting Virtuoso Featured Poster

lol

come on... give me a break... where's the competition spirit?? haha (not that i would like to compete with you... i'm certain you would beat the hell out of me...)

ndeniche 402 Posting Virtuoso Featured Poster

I'd wager the OP is not using C++.

there's where i will not agree... I can bet the OP is using Turbo C++...That's exactly the same kind of code they were making me use when i started on Turbo... that's why i came out with that solution... (actually that's what i did when the buffer was filled up...)

ndeniche 402 Posting Virtuoso Featured Poster

actually, i would recommend to use cin and cout, but i assume you are being taught to work with scanf and printf, so i will provide a secondary solution, which i wouldn't recommend to an experienced programmer...

printf("Do you want to continue?(y or no)\n");
getchar();
 scanf("%c",&answer);

i works perfectly, as i said... but i wouldn't use it myself...

ndeniche 402 Posting Virtuoso Featured Poster

what was that about? don't you hate it when users come here asking questions without even having investigated on their own, try to figure out what's their problem, or even read any of the many books about there are?

i mean... i ran into you guys after like three weeks of investigation, which became useless, since i found anything helpful 4 my project...

besides... we're not whining... we're just telling people, warning people that we are not here to do their works... we're here to help them open their eyes...

ndeniche 402 Posting Virtuoso Featured Poster

>which runs a WindowsXP OS....
It might start without crashing, but a lot of old programs start on Windows XP and don't work correctly due to their age.

I, as well, use Turbo (cause that's the one used @ the university [thing i don't actually like...]), and i installed it correctly and with no issues on two of my computers, which run, one Windows XP OS, and Windows Vista OS, and there's no problem for me using it... so i don't thing is the ancientness of the program...

are you sure you installed it correctly? have you tried installing it again?

You know, you could just say that you're being forced to use that compiler instead of being a jerk about it.

ooohh, yeah... i liked that... lol

ndeniche 402 Posting Virtuoso Featured Poster

o icic thanks um but what i was really wondering how does that work in the loop it kinda hard for me 2 picture it

i don't wanna be rude or whatever... but this is just the lamest way to waste our time...

you should want to read the book first... if that doesn't work, come to us... i can't imagine how a person that has read the book can come here to ask these questions... i mean... PLZ...

though, i will explain... any arithmetic operator will work EXACTLY THE SAME inside or outside any loop... so, y you have a "sum" variable created out of the loop and an assigned value of 0... (if you would have read the book, you would know...) "sum" would be your counter, or whatever you want to call it... so, what you have to do is

sum+=save

inside the loop just as Narue had pointed out several (many, indeed) threads ago...

It doesn't need a genius to figure that out...

ndeniche 402 Posting Virtuoso Featured Poster

exactly... we are just leading people into which way is correct... even, sometimes we will just write a line of code, because that's the oly thing we consider you'll have problems with...

come on peeps... we're not here to do your homework...

ndeniche 402 Posting Virtuoso Featured Poster

this may require you to check your capital letters in a separate array...

my idea of a simple process to do this is the next one:

1.- create an array that includes all capital letters.

2.-inside a loop, compare all of the letters in the string to both arrays (capital and non-capital letters), and convert all letters in the string to non-capital letters, so that you won't have any trouble further...

3.- to make it trouble proof, compare all of the users inputs to both arrays in a loop, and convert all inputs into non-capital letters

4.- compare the input you just converted with the word you want the user to find...

ndeniche 402 Posting Virtuoso Featured Poster

i've gone through some threads from people asking for help that have posts from these users saying things such as

still the program doesn't do what i want it to do

This is why i would like to say to all users:

When we post solutions to your questions, most of the time we will expect you to complete the program with lines such as cout, or printf, or write, etc... we answer your questions right where your problem is, but it's up to you to complete our solutions with code that is simple logic...

i.e. if you want a loop that will add up a series of numbers, we will provide the loop, but we may miss the part where the sum is printed... this is because we ASSUME you will be smart enough to know that part is missing...

thnx

Aia commented: Amen, brother -Aia +1
ndeniche 402 Posting Virtuoso Featured Poster

whenever you wish to print or store code that is recognized as system code (meaning it will not be printed) such as quotes in a printf or cout, or things like that, you must include a "\" before the code... i.e.:

\"
\\
\%

etc...

ndeniche 402 Posting Virtuoso Featured Poster
if(strchr(sentence, *letter[j]) != NULL) {
++num[*letter[j]];
printf("\'%c\' was found in \"%s\" %d times. \n",*letter[j], sentence, num[j]);

you are not using any counter to know how many letters you have. You should create a variable that will count how many times this process is true.

ndeniche 402 Posting Virtuoso Featured Poster

though, yo have not solved out what AD said... there's a lot of function in your inventory class that you should better use as general functions...

ndeniche 402 Posting Virtuoso Featured Poster

can any one tell me How the computer Reads it i mean how is the sontrol transfered plzzz

I think it would be better 4 you if you first learned how to use recursive functions b4 you tried one yourself... or is this some sort of benchmarking?

ndeniche 402 Posting Virtuoso Featured Poster

lol... ok... here's more specific ok?

i've seen you've worked out part of the solution... so, here's what you might want to do...

case 1:
   cout<<"one thousand";
   break;
case 2:
   cout<<"two thousand";
   break;
case 3:
...

by the way, i have a suggestion to make... why don't you better print only the quantity of thousands there are in the number, and, after the switch is finished you print "thousand"... (you should want to do the same thing with million, hundreds, etc...)

ndeniche 402 Posting Virtuoso Featured Poster

this looks like a simple recursive function, and that piece of code is the part where it returns the next value of the fibonacci series... i suppose before that there is a "cout<<" that calls the recursive function?

ndeniche 402 Posting Virtuoso Featured Poster

by the way... the correct way to wrap your code is using CODE tags

ndeniche 402 Posting Virtuoso Featured Poster

i will take my guess, and say you have low or no experience at all with c++... so... here's the deal... when you develop a switch, you write the code you want the program to run through in every case, and after every case, you write a break;, which will end the switch decision, and continue with the next part of the program...

Got it?

ndeniche 402 Posting Virtuoso Featured Poster

when we recommended you to change the functions we told you, we meant you to change JUST THE LINES WE WERE TALKING ABOUT... instead, you changed the call 4 the function and the function prototype... which had nothing to do with what we recommended...;)

ndeniche 402 Posting Virtuoso Featured Poster

as suggested before, you shoul (in the main() function) assign your int small the value of the function findLowest, so, later, you can send it as a parameter to the function calcAverage... that should do it...

ndeniche 402 Posting Virtuoso Featured Poster

thnx 4 the link... actually it's pretty interesting...

ndeniche 402 Posting Virtuoso Featured Poster

by the way... isn't it a rule to avoid posting your thread with names such as "Help" or things like that? Instead you should post threads with a title that sort of describes your problem

Salem commented: Absolutely! +6
ndeniche 402 Posting Virtuoso Featured Poster

Another point:
Why are you declaring average in main() and then passing as an argument? Just declare it in calcAverage() only.

i agree with anupam_smart, but you can save even more memory by not declaring average at all... just do

cout<<(((score1+score2+score3+score4+score5)-small)/4);
ndeniche 402 Posting Virtuoso Featured Poster

hmm... but, since my conio library didn't work correctly (Using Dev's c++), i managed to obtain a new library, with which i have to #include the "conio.c" file, instead of the usual <conio.h> file... and that's how i use my conio library ever since...

ndeniche 402 Posting Virtuoso Featured Poster

sorry about that... :D

ndeniche 402 Posting Virtuoso Featured Poster

well, it's pretty near to what i said, though that gave me an idea... why not make a fusion of both ideas and create two individual arrays with the size of the string: one with '_' in each element, and another one with the letters in the string in it. When the user's guess is correct, you enter a for loop and assign the user's guess letter into the matching places in array1 (the one with '_') and array2 (the one with the letters)...

get it?

ndeniche 402 Posting Virtuoso Featured Poster

why not better work it out an even more simple way... get your string's length and create an array of characters as long as the string, which will substitute your string in the rest of the program. This way you can compare your guess individually with each element in the array...

i don't know... maybe it can make things a bit more simple...

ndeniche 402 Posting Virtuoso Featured Poster

this way:

int N;
cout<<"Please input n";
cin>>N;
for(j=0;j<N;j++){
   temp=temp+temp+1)
}for(i=temp;i<n;i++){
   i=i+i+1; 
   cout>>num;
}

hope u don't mind i used ur code jimmymerchant...

but that's the way it will work with an user input...

ndeniche 402 Posting Virtuoso Featured Poster

but, did it work?

ndeniche 402 Posting Virtuoso Featured Poster

oooohh... i know where your problem is... when you call

calcAverage

you are using your variable "small" instead of the function you used to find the smallest... your code should go this way in line 12:

calcAverage(score1,score2,score3,score4,score5,
findLowest(score1,score2,score3,score4,score5));

or, the other way around, you could do this before calling your calcAverage function:

small=findLowest(score1,score2,score3,score4,score5);

which will work exactly the same...

got it?

ndeniche 402 Posting Virtuoso Featured Poster

another thing... why are you using

int small

as a parameter in calcAverage?

ndeniche 402 Posting Virtuoso Featured Poster

this is because you have a small mistake right in the end...

erm... you aren't using four scores... you are actually using five scores...

ndeniche 402 Posting Virtuoso Featured Poster

when optimizing for speed, one very useful thing to do (as mentioned above like infinite times) is reduce the amount of lines in your program... since the compiler runs through less instructions, which takes less time to do...

ndeniche 402 Posting Virtuoso Featured Poster

exactly.. from wat i`ve heard unsigned takes more cycles than signed ...

its not that it takes more cycles (correct me if i'm wrong)... its just that an unsigned variable uses the memory that is not used innegative numbers in positive numbers... i.e.:

int n

goes from [-32767,32767], and

unsigned int n

goes from [0,65534]... right?:-/

ndeniche 402 Posting Virtuoso Featured Poster

it's not that unsigned takes more cycles that signed 8correct me if i'm wrong), but the thing is that the space unsigned variables do not use in negative numbers is used in positive numbers... i.e.

int n

goes from -32767 to 32767, so, logically

unsigned int n

goes from 0 to 65524... right?

ndeniche 402 Posting Virtuoso Featured Poster

why dn't you use a much simple (though longer) way to do this... this would be the "amateur way":

char string[]="31.245¨;
char num;
double div=1;
float number=0;
num=string[0];
int i=0,decimal=1;
bool p=false;
while (string[i]!='\0'){
       num=string[i];
       if ((num=='0')||(num=='1')||(num=='2')||(num=='3')||(num=='4')||(num=='5')||(num=='6')||(num=='7')||(num=='8')||(num=='9')){
      number=number+float(atoi(num)-(atoi(num)-1));
      number=number*10;
       }else{
             p=true;
       }if (p)
             decimal++;
       }i++;
}for (int i=0;i<decimal;i++);
   div=div*10;
}number=number/div;

and there it is...

it's not the best way to do it, but it works... personally i would not recommend u 2 use it... but, if nothing else works... it's better than nothing... it could keep u out of an emergency...

ndeniche 402 Posting Virtuoso Featured Poster

there's another solution a bit more complicated than the one from salem (wich is pretty simple, nonetheless pretty accurate to your question), but i'd rather create a temporary array, transer the files from array1 into array2, delete array1, create (again) array1[size-1], and transfer again all information, but the element you wish to remove.

This is pretty useful when you use large arrays and you wish to print them or use them in other processes (with a loop) that could/will use the entire array... this way, you have the amount of elements you need in your array, and you don´t have to worry about the last elements being the same...

This may also work when adding an element to the array, except that when you create the array again, the size must be [size+1], and then you read the information for the last element...

ndeniche 402 Posting Virtuoso Featured Poster

besides, you should consider:

-- using the right type of variable, meaning, if yyou need to use decimal values in your program, if they're not too big, consider using float rather than double...

-- (where you can) using pointers instead of arrays, since it uses less memory

-- being specific and simple in your processes, meaning you develop in 10 lines of programming what, with another process working just the same, you could use 25.

-- cleaning useless information off the buffer

-- using struct arrays instead of single variable arrays where you can

and such things that may seem simple, but can optimize your memory usage

ndeniche 402 Posting Virtuoso Featured Poster

there's a function in <cstdlib> called strtof (string to float) which can perfectly do that...

ndeniche 402 Posting Virtuoso Featured Poster

Hopefully, because of this :icon_wink:

The thing is, i always take care to make my programming "stupid proof", and this way, if the user makes any mistake at entering his/her answer, such as entering "yes", it will not fill up the buffer and screw up the program... maybe if when using the

if (getchar()=='y')

you flush the buffer before the next input... ;)

ndeniche 402 Posting Virtuoso Featured Poster

about reducing the decimal points, if you include numbers before the f in %f, you will obtain the amount of digits after the period as you specified. i.e.: %1f will display "69.3"

%2f will display "69.27"

ndeniche 402 Posting Virtuoso Featured Poster

when you use the library stdlib for the input/output commands, and you need to print decimals, you need to be careful on printing (as AD says) %1f or %2f (to display hundredths), instead of %d, since in %d it only displays whole values, not partial ones.

ndeniche 402 Posting Virtuoso Featured Poster

why don't you try using

cout<<"\a";

?

ndeniche 402 Posting Virtuoso Featured Poster

why don't u better use a CHAR as a centinel? like this:

char ans;
   do{
      (program)
      printf("Do you wish to enter another temperature?");
      scanf("%c",&ans);
      }while ((ans=='y')||(ans=='Y'));
ndeniche 402 Posting Virtuoso Featured Poster

nope... what i´m saying is that you s1 into s3 in the first cycle with a while loop. Then, without moving the pointer from the position next to the last character you entered in s3, you continue with s2, transferring characters into the rest of the spaces in s3, and in the end s3=='\0' like this:

while (*s1!='\0')
   *s3==*s1;
   s1++;
   s3++;
}
ndeniche 402 Posting Virtuoso Featured Poster

the thing is, in this function you are not concatenating the two strings, you are adding together two pointers, which does not solve the problem. what you must do is create a

char *s3

with the length of the two strings added together, and pass the characters one by one into the pointer...

Got it?

ndeniche 402 Posting Virtuoso Featured Poster

what you need to use is a for(), since it is better because you can instruct the cycle to do the procedure as many times as you want. Like this:

double x,multiplication=1; //create a second variable so you won't lose your x value
for (int i=0;i<n;i++){
   multiplication=multiplication*x; //multiply your x value to your stored multiplication in the variable you created
}

or if you were using a while(), you could do it this way:

double x,multiplication=1,i=0; //i is your centinel to stop the cycle
while (i<n){
   multiplication=multiplication*x;
   i++;
}
ndeniche 402 Posting Virtuoso Featured Poster

it would be very useful if you wrapped your text in code (

)

ndeniche 402 Posting Virtuoso Featured Poster

maybe you should make this function a void function and not an int function, this way you print the scroes in the function, without returning anything.

ndeniche 402 Posting Virtuoso Featured Poster

First of all... what is the value you are telling the function to return? The third message means you cannot put a void function to be returned as an int function, so that's why you cannot tell the program to return "cout "

ndeniche 402 Posting Virtuoso Featured Poster

actually, what AD says bout the max/min value is absolutely the best way to do this. You just have to assign the value in the first variable to another one,so you can compare with if´s, so if it is lower than the temporary variable, you assign the value you just compared to this varuable and continue comparing.

As for the getScore function, you should initiate the 5-scores variables outside of the main, so they are general to the whole program, so you ask the user for them inside the getScore() function.

Now, the calcAverage() function should not be a problem.