csurfer 422 Posting Pro

Have you by chance come across the phrase called "Compiling The Program" ??? I can definitely say that you haven't even compiled the program.
Because you have missed out on the very basic of which characters are allowed to form a variable.Since when did n1-factorial a variable and not variable n1 - variable factorial...???
And there are also many ambiguous calls in your function.

To solve these just compile your program on a good compiler.And debug the bugs.

csurfer 422 Posting Pro

1)

if(input=="A" && input=="a")
//Same applies to all other vowel statements also

2)

a=a++;
//Same applies to all other vowel statements also

The two most foolish statements in your code are the ones shown above.

1) What you really want to do is to compare every character of string input with character 'A' and 'a' . But you are taking the whole "input" string and comparing it with string "a" and "A". That means you will never get anything more than 0.

2) This is a bit complicated concept called sequence points.In case you want to know you can read it.

Generally when we try to manipulate the same variable more than once within a sequence point the result is always compiler dependent.It can be anything.Moreover here a++ alone efficiently replace the whole statement (2).

csurfer 422 Posting Pro

Ive been reading alot of threads and im getting the impression that students asking for help and getting it is like a taboo. "NO homework allowed".... but now i see that there are people on this forum that will help and when i get the a better level in programming i will be willing to help.

You have a very wrong impression about DANIWEB and the culture here... We don't say "No Home Work" we say "We wont help until you put in some effort",and even you would agree that we are not wrong.

We are here to learn and to help others learn. And none here are workless and come here for fun. Everyone is really busy but take some time out to help others who want to learn, so have a bit of patience.

And ya NARUE was the one who guided me when I was new and helped me a lot and DANIWEB is the reason for what I am.

csurfer 422 Posting Pro

Why did you post the code here...???

csurfer 422 Posting Pro

You need to pay more attention in your classes.Very silly mistakes.

1)

vowels::vowels ()
{
	int a=0; int e=0; int i=0; int o=0; int u=0; int y=0;input="";
}

Class functions are used to manipulate the variables declared within the class.Here by declaring the variables again you are just removing the whole sense out of it.You just need to initialise the variables declared within the class.

2)

if(input=="A" && input=="a")

If input equals 'A' how in the world can it be equal to 'a' at the same time....??? And && requires both the condition to be true.What you really need here is the"||" "or" and not "&&" "and".

csurfer 422 Posting Pro

Your customers function is a total mess.

Apart from the errors mentioned by Ancient Dragon and jonsca above I felt these were wrong.

1) The criteria should be matched with a previously available list of customers but here you are creating a new customer list which totally makes no sense.
2)setID() class function is setting an integer itself because char of value 1 and 2 make no sense in this context.So obviously getID() would return an integer itself and you are matching it with a character as

if(s[i].getID() == critera)
csurfer 422 Posting Pro

May be a printf within a printf would do the trick.Because the inner printf doesn't require the semicolon.

csurfer 422 Posting Pro

Ok code it... Conceptually everything is right.

csurfer 422 Posting Pro

These are the steps:

1)First write a program to dynamically allocate memory for a matrix,input values to it and print them.
2)Now take a pen and paper and find the inverse of that matrix step by step.
3)Analyze the steps and code for it finally.
4)Correct the mistakes which you might have done.

csurfer 422 Posting Pro

Here is your faulty code :

for(;k%5==0;)
                       y++;
k++;

Your k%5 checks if its value is 0 until its not zero k++ executes very well.Once k becomes a multiple of 5 then the for loop

for(;k%5==0;)
                       y++;

Will never quit because you will increase y , and k's value is not altered whatsoever.

csurfer 422 Posting Pro

Definitely no need of looping required.Its a simple four step procedure.

1 ) Read the entire line into the character array say str.
2 ) Check if string length of str is greater than 22 or not.
3 ) If no then cout << str ; .
4 ) If yes then str[22] = '\0' ; and then cout << str ; .

Loop through the above 4 points until end of file.

csurfer 422 Posting Pro

@somaja : Ya ya you have caught our attention , now can you please stop using the BOLD RED COLOURED text...??? And ya use code tags when posting your code.

@somaja & squ : Post in your progress in solving the program till now you will definitely get help from our side.

csurfer 422 Posting Pro

Post by jonsca and tux4life have divulged all the information related to this topic.But would like to add some from my side.

Apart from the printable characters (character which can be seen on a output screen) we make use of several other operations when working on any text.
When we work on a text editor,the text editor handles all the operations on its own and keeps us away from implementation details.But in C those operations are included in the character set itself so that a user can make use of them and format his/her output in any way required.

These characters which hold a very special meaning and work instead of functions as in text editors are your "Escape Characters".

Every letter has its identity. Say character 'A' instructs the machine to store value of 65 in 1 byte to symbolise 'A'. In escape characters we tell the compiler to escape or neglect the meaning of original character and act differently by placing the '\' symbol before it.Hence the name "Escape Character". You can try something like:

cout << "TestString1__TestString2";

and place '\a' '\b' '\c' ... and so on and test what every character does.

csurfer 422 Posting Pro

today is my last chance plz help.

Today is your last chance so you please try...

csurfer 422 Posting Pro

Here we show the path for you to follow,but don't code for you. When I gave you the C implementation of the code I thought you will keep it as a guideline and hence implement it in C++ in your own way by using std::string class , but you are being lazy and using the same code. Why should I give you the C code,I can write the whole program in C++ directly if I want to.

If you want to learn the language stop being lazy and try.

We are not here to do the lob of online compiler for you.Try to solve your problem yourself and then when you reach a dead end in one of the problems ask us for help...Till then Happy Coding :)

csurfer 422 Posting Pro

how to convert this program in object oreint ???and how to use stuctures in it.???????......how i can do inheretence in this program ???????????.........how to make the user in put case senstive in c++????????????

Use the class concepts and use objects hence you will make it object oriented.

After using classes you can use inheritance concepts.

If you compare characters then it will definitely be case sensitive. As ASCII of 'a' is not equal to ASCII of 'A'.

csurfer 422 Posting Pro

Ya lots of ideas... but cant express it until you show your code...

csurfer 422 Posting Pro

okay...thanks for your help... n_n

Ya once you feel your objective is served then close the thread, so that others can concentrate on other threads.
Read the forum rules on using the code tags.And you can also vote posts and persons positively and negatively all this is mentioned in the forum.Go through it and ya Welcome to DANIWEB !

csurfer 422 Posting Pro

@Tom Gunn : ;)

You have a strange idea of what is and is not C++. The headers are all messed up, but if those are fixed to match what is actually used, it is all C++. Here are the right headers:

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>

What you say is definitely one view of the code,I agree. But any language has its essence in its implementation rather than the headers it uses.

Op's code has declared <vector> header but no use of it has been made.It has the header <fstream> but instead of the various easy to use file handlers file pointers have been used as in C.

So at one point I felt that this has more of C rather than C++ and thats what I told OP because this is a C++ forum.

@Web_Sailor : The mistakes are clearly specified in my previous post and none of the errors are very difficult to resolve, the probem within the isnum function can be solved by :

if(!isdigit(*str))
{
cout << "Invalid format" << endl;
return false;
}

And similarly others too...

csurfer 422 Posting Pro

Never done it before ? Very good try it now !!! Only then you will learn...

Well in C you would do something like :

FILE *f;
char str[100],*str1="file",*str2=".txt";
//You have count and file<count> is the file you want to open
sprintf(str,"%s%d%s",str1,count,str2);
f=fopen(str,"rw+");
//Go on with your writing work

Now try the same thing in C++.Try to implement it on your own.Only then can you learn something.

csurfer 422 Posting Pro

You don't need to use the reference variables at all as char calculateGrade(int& avrg, char& grade) This is enough :

char calculateGrade(int avrg)
{
char grade;
//After this same function definition as you have done no changes...
}

And now comes the change part...With the above code you cannot use

calculateGrade(avrge,gd);
cout <<"Grade is : "<< gd<<endl;

To output your grade...
Firstly the function call would be calculateGrade(averge) This function returns a character which is your grade.

Here I leave you on your own, Try to find out where and how to modify in your main function to achieve your objective.

csurfer 422 Posting Pro

There is nothing C++ in this code apart from "using namespace std","cout","bool".

You aren't using the isnum function at all as its not used in any decision statements even when it returns true and false.

Your isnum function itself id flawed.

if(!isdigit(*str))
cout << "Invalid format" << endl;
return false;
str++;

return false is left out of the if block and would be executed irrespective of the result of the condition isdigit(*str).

Even with all this your if your code works then its definite that you wanted to go somewhere but have landed somewhere.

csurfer 422 Posting Pro

You are using integers to store the factorial of a number and obviously 13! 14! 15! will go out of integer range. It definitely overflows and that is the reason you are getting erroneous outputs. try changing the variables to long int or double and you will get the desired output.

csurfer 422 Posting Pro

@sparksterz : No you should not use system("pause") to view the output.It has been discussed here a lot number of times. You can use cin.get() instead and it too will work in the same way.

@yuha : Not one there are several things wrong with this code.

1) Usage of <conio> which is already extinct.
2) Usage of std::cout std::string etc is required, or atleast usage of standard namespace as

#include<iostream>
using namespace std;
// Code continues...

is required.
3)Using int main and return 0 at the end instead of the void main().
4)Your calculateAverage function is flawed it doesnt calculate the average at all.

void calculateAverage(int& average)
{
int sum=0,score;
cout<< "Enter all of the test score: " << endl;
for (int i = 0; i <5; i++)
cin >> score;
cout << score;
sum = sum + score;
average = sum/5;
}

the above two statements are not included in the for loop at all and so you'll never get the average.It should be

void calculateAverage(int& average)
{
int sum=0,score;
cout<< "Enter all of the test score: " << endl;
for (int i = 0; i <5; i++)
{
cin >> score;
cout << score;
sum = sum + score;
}
average = sum/5;
}

5)Your grade function needs a lot of restructuring so that it outputs the right grade.

csurfer 422 Posting Pro

Lots of problems only in pointers.

1) Yes you guessed it right the declarations should be of form <function>(char *) format.
2) Consider the following example:

void function(char *a)
{
    // Function Definition
}

// Somewhere in main

char arr[20],a;
char *p;
p=&a;

// Call can be either like
function( arr );
// Or as
function( p );

the criteria is that to a pointer variable you pass the address which it should hold and operate upon.Major flaws with regard to this concept and not the value that the pointer holds as you have colled function(*p) and function(*arr) .

3)Consider the following :

char *p;
// A pointer is created which doesn't point to any memory address.
*p='a';
//trying to put a value into the address pointed to by pointer 
// results in a error as pointer doesn't point to any memory address.

Proper code is:

char *p,a;
p=&a;
*p='f';
csurfer 422 Posting Pro

He posted his code in the Geek's Lounge for some reason. Without code tags of course. ;)

Is that so...??? I didn't know it... Thought he too is one among those guys who post their requirements and ask us to code... ;)

csurfer 422 Posting Pro

Its no coding secret or something but a simple formula kind of thing here it is :

For two numbers:

max( a , b ) = ( a + b + abs( a - b ) ) / 2

For three numbers it is:

max( a , b , c ) = ( a + b + c * 2 + abs( a - b ) + abs( a + b - c * 2 + abs( a - b ) ) ) / 4

csurfer 422 Posting Pro

Ya Sure...
Our Assignment Delivery Boy will come over to your house in another 30 minutes and deliver you the assignment along with the free things which we have offered.Please pay him the amount in cash.Good Day !!!

csurfer 422 Posting Pro

Ok ... So ?

csurfer 422 Posting Pro

Waltp and Campbel are right in their concepts but you can still decrease the numbers from which you divide.

If the number you need to check is "num" then divide num with 2 and every odd number form 3 upto [ ( int ) sqrt ( num ) + 1 ] (both inclusive) this decreases the count of candidate numbers more than n/2 and yet still gives the answer.

@Campbel : you are majorly wrong in your program , your candidate numbers start from 0(loop starts form 0).This is the biggest mistake you have done.
1)It would cause an overflow when a number is divided by 0.
2)Every number is divisible by 1 hence it would never show a number to be prime.

Good effort but show a bit of caution when guiding others. :)

csurfer 422 Posting Pro

What first person has said is right about the wrapping but the example given is wrong as it quits the loop on every input 0 or 1(at least according to gcc 4.3).
the error is in the line:

char quit = false;

You cannot use a character variable to hold a boolean value.So to correct this mistake and to successfully convert the above statement to either of these:

bool quit = false;
//or
int quit = false;
csurfer 422 Posting Pro

You can take the player class as :

class player{
private:
string name;
int goals_taken;      // Keeps count of goals taken
int shots_taken;      // Keeps count of shots taken
int num_streaks;    // Keeps count of streaks
int num_slumps;    // Keeps count of slumps

 // Keeps count of matches continuous where goals have been taken
int count_positives;
// Keeps count of matches continuous where no goals have been taken
int count_negatives;

//Here the positive counter goes on increasing if the player scores at least a single  
//goal in a match and is set back to 0 either if the counter reaches 5 where the streak 
// count is increased by one or when a loss appears in between.
//The negative counter increases when a player doesn't score a single goal in the 
//game and is set back to 0 either when the counter reaches 7 where the slump //count is increased by one or when there is a win in between.
public:

//All the functions required to get the above concept to work.

};

You can use this class and can simulate the whole thing you have mentioned above.

csurfer 422 Posting Pro

Whenever you define a string as

char str[]="Hello\0MIster\0HowAre You?";
printf("%s",str);

Every time the compiler stops outputing the characters of the string to the output console once it encounters a '\0' character.So even if you put '\0' character in place of ' ' character this won't do any good.
Instead you can use an array of character arrays and store every generated string in order.

csurfer 422 Posting Pro

They have mentioned everything so clearly... Use if else or if else ladder to find the ranges in which the given temperature falls and print accordingly...

csurfer 422 Posting Pro

Why not?

For several obvious reasons Tom Gunn :

1)Because it is sub standard.
2)Uses all the extinct headers and commands.
3)It is not according to the c99 standards.
4)void main is valid in it.
5)The blue screen irritates a lot... ;)
And loads other stuff.........

csurfer 422 Posting Pro

First thing I don't see the purpose of this program as to what it does or is intended to do and apart from it this isn't a psuedocode,this is a C++ code itself other than some erroneous brackets which you can obviously correct by finding a matching pair of brackets for each bracket.

csurfer 422 Posting Pro

how do you do that? I'm really sorry.

Well study about getline() here. After doing it successfully you can change the getline function as per the format of your file and get your work done... Try it sincerely and post your queries here.You'll definitely get all the help required as long as you show some effort.

csurfer 422 Posting Pro

Thanks for posting your assignment/homework for us to work on....

But there is one tiny bit of problem...

1)This isn't the JAVA forum.
2)We never do others homework we just help them to do it on their own.

ACTUALLY TWO....

Ezzaral commented: But other than those two problems it is a great thread! :) +9
csurfer 422 Posting Pro

Just use srand() and rand() commands for more information and how to use them do research on them.

csurfer 422 Posting Pro

Its ok no problems...You can start reading now and post all your doubts here... You'll get help definitely...

csurfer 422 Posting Pro

First of all your code here is incomplete and doesn't serve the purpose until further alterations. Second if you are sure of the three columns present then instead of ">>" getline with specific modifications to fetch the columns separately and store it in different arrays and then calculate their average.

csurfer 422 Posting Pro

Please put in the code and mention the area in which you are facing troubles and then ask us... In this way we can help you better...

csurfer 422 Posting Pro

Show your work... We will surely help you.

csurfer 422 Posting Pro

Is there a website I can go to or something? I am using my intro to C++ book and notes from class, but it all seems so foreign to me. I cant seem to make heads or tails of what I am suppose to do.

GOOGLE is your friend... try asking it and also this website is good ... And you are presently in a place where you can learn anything... DANIWEB.

csurfer 422 Posting Pro

Actually didn't get what you wanted to say...

csurfer 422 Posting Pro

I am trying to learn... The instructor told us to use
If (condition)
Then (condition)
Else (condition) optional
end if.

Its something called pseudocode which tells you how to code ... but you need to code it according to language rules... that you haven done....

csurfer 422 Posting Pro

For the file you have shown :

//includes
//defines
int main(void)
{
//Variable declarations
//File opening in input mode handler myFile say
char str[256];
myFile.getline(str,256,'\n')
//Scan through str character by character and find the number of '\t' characters say c_cnt therefore c_cnt+1 gives you number of columns.
r_cnt=1;
while(getline(str,256,'\n')) r_cnt++;
//r_cnt gives you row count.

You wanted an example and here it is ... you have to develop this module to an actual code and remove the bugs if any during implementation so that you can learn coding it on your own.

csurfer 422 Posting Pro

Backing up what niek_e said :

You have used c[i].GetName() in your for loop, you can use c.<function name> only if the classes are declared as Customer c[3] or something else you should use the functions as
c1.<function>();
c2.<function>();
c3.<function>();
separately as c1.function(); is completely different from c[1].function();

Ok and now for comparison of two strings you can use "==" as niek_e suggested (your mistake is using "=" instead of "==" )as it has been overloaded in the standard namespace.I hope now you understand.

csurfer 422 Posting Pro

Are you allocating the memory for the stack dynamically...?

csurfer 422 Posting Pro

I thought reading the number is what I was doing in line 12.

Yes you are reading the number in line twelve then what sense does it make to compare the number to be within some limits in line 11 itself....???