csurfer 422 Posting Pro

I may be wrong but as far as I see you are using a single port to receive client requests from , but later when you intend to handle different clients in different threads you have to bind them to a different port for the connection to remain intact and communication to take place. If all threads are linked to the same port and you close that port all the connections are bound to get disconnected.
As its been some time that I have programmed in this field I may have gone wrong somewhere. Do correct me in case I am wrong.

csurfer 422 Posting Pro

Close the thread if you are done with the question.

csurfer 422 Posting Pro

The error message itself says where you went wrong.Initialization of factorPtr in line 14 should be factorPtr(ptr) rather than *factorPtr(&ptr).

csurfer 422 Posting Pro

You want the address of the variables list1 and maxVar to go so your summarr function call be like

result = sumarr(arr, num, maxVarHolder);
csurfer 422 Posting Pro

You have interchanged rows and cols in for loops of your print_array function,and its an obvious core dump. Change that and your code (with the changes I have made in my previous post) works.

P.S : Try to solve such simple problems by looking at your code more cautiously. Its your code, your brain child you should atleast spend some time knowing it :)

csurfer 422 Posting Pro

I just made some small change in your class definition removing the .resize() and fill() functions as I didn't find their need.

template <typename T>
class dyn_arr{
public:
        //Dedault constructor
        dyn_arr() {};
		//Constructor
        dyn_arr( int rows, int cols)
        {
            for(int i=0; i<rows; i++)           
			{
				vector<T> row; // Your mistake was hardcoding int here as vector<int> as it will need vector<string> here
				for(int j=0; j<cols; j++)
				{
					row.push_back("hello");
				}
				arr.push_back(row);
			}
        }

        void print_array(int rows, int cols)
        {
			for(int i=0; i<rows; i++)
			{
				for(int j=0; j<cols; j++)
					cout << arr[i][j] << "\t";
				cout << endl;
			}
        }

private:
        vector<vector<T>> arr;
};

And ya if you are using it as a string array (dynamic) dont forget to include <string> header file.And it works. :)

Fbody commented: Here's a vote back. Good Catch. +4
csurfer 422 Posting Pro

This is definitely not an exam question its a question picked up from some coding competition or as the "Note:" section says that its an assignment as it speaks of the submission and the criteria to be met before the submission.

Anyways these type of question normally follow a format as to number of test cases followed by important data of the question(here N and K) and then the detailed data(Here the blood group).As :

2
4 2
1 1 4 7
6 3
1 4 8 12 16 20

Here it means that it has two test cases as the first line signifies TC's.
Then the test cases follow where first line of TC has N K format then the N dragons blood group in the next line.So on and so forth for all the other test cases to follow. Now you know how to take inputs come up with your algorithm to solve it :)

csurfer 422 Posting Pro

This is definitely not an exam question its a question picked up from some coding competition or as the "Note:" section says that its an assignment as it speaks of the submission and the criteria to be met before the submission.

Anyways these type of question normally follow a format as to number of test cases followed by important data of the question(here N and K) and then the detailed data(Here the blood group).As :

2
4 2
1 1 4 7
6 3
1 4 8 12 16 20

Here it means that it has two test cases as the first line signifies TC's.
Then the test cases follow where first line of TC has N K format then the N dragons blood group in the next line.So on and so forth for all the other test cases to follow. Now you know how to take inputs come up with your algorithm to solve it :)

csurfer 422 Posting Pro

@AncientDragon : Sorry your message was not uploaded when i started writing the post. :)

csurfer 422 Posting Pro

cout always looks out for a type which it can output or another object of its own data type that is "ostream&" but you are passing a void type to it by using the myObject.displayObject() in line with cout.Rectify it and you are done.

csurfer 422 Posting Pro

State your question properly . And show us some code that you have tried to write...

csurfer 422 Posting Pro

@myk45:

Just explaining what gerard4143 said in simple words.

First usage is allowed as what ever usage of pointer you make its still remains a pointer and takes up a standard amount of memory which is normally equal to the size of your integer variable.So it can be defined without any confusions.

In the second usage you are including a variable of the same structure type inside the structure. Now here in order to declare a variable of some data type you need to know how that data type is defined and the data type cannot be unambigiously defined until the compiler knows what all the variables within that structure.So one waits for other and no one gets completed.

But this is allowed

struct A
{
     int a;
     char b;
};
struct B
{
     int c;
     struct A varA;
};

As the definition of A knows how char and int are defined and their memory needs and before structure B is defined the compiler knows how structure A is defined.

csurfer 422 Posting Pro

Before worrying about big things please pay some attention towards small things...
There is a lot of difference between 1 and '1' .
The input you are taking is a character so the cases of switch should be as case '1' : case '2' : and all , else make the input to be taken to a integer rather than a character.

And ya usage of fflush(stdin) is bad. One more point of concern is all the inputs you are taking doesn't actually need a space and hence you don't even need to use getline().You can directly use cin >> temp1; 4 posts without even concentrating on the main problem.This way you will add all the statements in this world but still wont be able to take the inputs.

amrith92 commented: Well Spotted! Man am I blind!! +2
csurfer 422 Posting Pro

OK here it goes.The piece of code provided by you works on the character buffer from which "cin" reads from, rather than the actual number 42.

Take the example of input of number 10.
It is treated as '1' '0' '\n' ,ie 1 followed by 0 followed by 0 followed by no character.

loop 1 : d=10 c not assigned

condition 1) When it enter the loop first condition to be checked or executed is cin.get() which fetches a character in this case '1' .Therefore c='1'

condition 2) c!='2' and d!='4' which is true

condition 3) print d ie here the character '\n' of ascii 10.

So finally you will get a newline. and then d=c

Loop2 : d='1',c='1'

c1) cin.get() therefore c='0'
c2) c!='2' and d!='4' is true
c3) Print d hence prints '1' , then d=c

Loop3: d='0',c='0'

c1) cin.get() therefore c='\n'
c2) c!='2' and d!='4'
c3) print d,therefore prints '0', then d='\n'

Now as there are no more inputs to read in the buffer until the buffer gets newly filled by some other characters the cin.get() waits and hence the while loop waits.
As we have already seen the first input 10 has already been printed and d holds '\n' and waits to print it.

Assume our next input is 42 taken as '4' '2' '\n'

Loop4 : d='\n' ,c= (un-assigned) <same as the first loop condition>

c1) cin.get() therefore c='4'

csurfer 422 Posting Pro

Hi this is the code for life, universe and everything problem, where the program stops only when the user inputs the number "42"

I tried to understand the problem, but could not make it that how the program stops at exactly 42. Any help would be extremely appreciated.

#include <iostream>
 
int main(void) {
char c, d=10;
while(std::cin.get(c) && (c!='2' || d!='4') && std::cout.put(d))
d=c;
}

First thing who told you to take it as a character...??? You just want to stop on 42 right take it as a integer and compare.

csurfer 422 Posting Pro

csurfer...howz that possible...i mean can u give the syntax plz...


william...this isnt working..i tried it out...

Well what I meant was something like this :

#include<stdio.h>
int main()
{
       printf("%d%d",printf("Hello Daniweb"),printf("I am new here"));
       return 0;
}

You would get an output as I am new hereHello Daniweb1313 The inner printf's are not using a semicolon as you can see.

"printf" function returns the count of characters it has successfully output on the console and it processes from right to left internally hence first it print I am new here and then Hello Daniweb and then count of the successfully output characters of each string which in this case is 13 13.

csurfer 422 Posting Pro

This OP deserves an applaud, he is so honest that he is directly giving us his assignment copy and asking us directly to code for him. :D

Really sorry,here your honesty doesn't pay you the code you need.You need to work.Work hard and code yourself.

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

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

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

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

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

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

@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

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

Here are your Errors...

Err 1:
Line 67 :

scanf("%d", operation2);

It should be

scanf("%c", &operation2);

Err 2:
Your macros are completely useless in this case.Even though you can change them to correct the mistake I would suggest an alternate way.

scanf("%c", operation2);
				
/* uss a switch case structure to use the user input calculator math */
switch (operation2)
{
                case 'a': 
		case  'A': total = num1 + num2;
			operation = '+';
		break;

                case 's': 
		case 'S': total = num1 - num2;
			operation = '-';
		break;

                case 'm':
		case 'M': total = num1 * num2;
			operation = '*';
		break;

                case 'd':
		case 'D': total = num1 / num2;
			operation = '/';
		break;

               case 'q':
		case 'Q': 
			total = num1 % num2;
			operation = '%';
		break;

		default: printf("Invalid Letter selected\n");
}

Err 3:
What you are doing is mixing the concepts.Don't do it. Try to clarify your doubts and have a clear conceptual of MACROS and where they are used and where do we need to sue variables.And ya also try to have a look on why fflush(stdin) is bad and should be avoided.
You'll always find help in this community as long as you show some hard work from your side.

csurfer 422 Posting Pro

What Ancient Dragon has suggested is a wonderful suggestion try to implement it but it is completely inconsiderate with the problem in your code...

In your code :

for (int i = MAX - 1; i >= 0; i--)
        cout << output[i] << endl; //Compiling error
        if (i % 8 == 0)
            cout << "   " << endl;

This for loop is the one which is causing the error.Here even though

if (i % 8 == 0)
            cout << "   " << endl;

part should be inside the for loop according to indentation,it wont be considered inside the for loop and would be considered as this:

for (int i = MAX - 1; i >= 0; i--)
        cout << output[i] << endl; //Compiling error

 if (i % 8 == 0)
        cout << "   " << endl;

But when treated like this variable "i" is not at all declared in the function as the scope of "i" ends as soon as the for loop is over.

Therefore correct your code as this :

for (int i = MAX - 1; i >= 0; i--)
{
        cout << output[i] << endl; //Compiling error
        if (i % 8 == 0)
            cout << "   " << endl;
}

and it will work in the way you want it to work.