i recently started programming. i mean I've been exposed to programming for the first time about a week ago. I've been following the tutorial here and playing around with my own code. For some reason, this code works while receiving decimals but not fractions.
Code:
#include <stdio.h>
int main()
{
float kd;
float kd_2;
printf("Please enter your k/d
");
scanf("%f", &kd );
}
I am having trouble in reading my full name in just a single variable and some kind of authentication. this is my code by the way.
Code:
#include <stdio.h> int main(void) { char NAME_MINE1[40];
void clrscr(); }
[code]....
if i enter my full name i will be able to go on to the next statement/command but when i put on some name (which is not mine) i will automatically get an error and exit the program.If i type "Qwerty You Tube" EXACTLY and not just the first string before the whitespace i will be able to proceed but when i enter "Qwerty Tube You" or "Qazse Qop Queen" i will get an error and the program will exit.
I'm still having troubles connecting multiple clients to my server.To break down what I have going:I have a server that is supposed to accept multiple clients.. Currently, It works with one person.While the server is running, One person is allowed to play the game (While connected to the server). If the server is down, the player cannot play (This shows that the server and client responde and work).
However, While the server is running and the client joins, the first player is allowed to play. Everyone else's window goes black and says "Not Responding" (Like any other game in which isn't working).While these players are in "Not Responding", It still says the client has connected onto the server (But they're not able to play?).My client code is working perfectly, But i'm having troubles accepting multiple clients onto my server.
#include <iostream> #include <winsock2.h> #include <vector> #include <process.h> #include "Included/pthread.h" //Some things i'm using or will be using in the future
My problem is that I've created a Client and Server program in which they communicate. The Client is an SDL Application that allows you to play as a movable character IF YOU ARE CONNECTED TO THE SERVER. If not, You're unable to play. THIS WORKS!
However, Only one client is able to play on my server?? Anyone elses' window freezes and they are not allowed to play (As if not connected to the server). Here is my server code.
which adds two rational numbers in following representation : rNumber := s*(n/d)* 2^e struct rNumber{ _byte_t s; // sign (do not consider for this question) uint n; //numerator uint d;// denominator short e;//exponent }
If the exponents of both numbers are not equal, then they have to be made equal in order to add them. This can be made in 4 ways : increase or decrease the n or d of both numbers.
But if we decrease the denominator of a number (a.d =1) by shifting it for example 1 bit to the right, we get 0 which leads to INFINITY for the fraction. In another case decreasing the numerator would lead the n to be 0 which meanse the whole fraction is then 0.
According to this, in worst case, all 4 cases has to be checked for the right result.
So far the UNDERFLOW of n or d is considered. If we try to increase the value of n or d, then OVERFLOW may also occur.
The very first, intuitive solution would be iteratively increase/decrease one of the terms and to check if the change leads to ZERO or INFINITY.
I'm looking for a library that handles rational, irrational and trascendental numbers and calculates the exact results without approximating values. For example, if I want to calculate:
a = pi; b = 3; c = 2;
I want this library to return the result in this way:
sqrt(b*c)*a == sqrt(6)*pi
instead of
sqrt(b*c)*a == 7.6952989
In case it matters, I'm working on Ubuntu and I compile with g++.
I'm pretty sure a library like that exists because it's too useful, I researched it but couldn't find anything.
I was trying 2 write a program that would calculate the sum notation of 1/(i^2) with the starting number to be 1 and goes up to the nth term. For instance if the user inputed 3 then the sum would look like 1+1/4+1/9. I somehow made a code but it gets weird numbers which some include negative numbers... when I input a number that is above 5.
#include <stdio.h> #include <math.h> int main(int argc, const char * argv[]) { int n; register int i=1; float b;//For part 1
[Code] ....
For some reason I can't edit printf("%f",/>/>; when I post it as the topic so ignore that part cuz Ik its supposed to be written as printf("%f",/>;
I'm working on a Fraction Class assignment where I'm supposed to provide conversion operators to allow Fraction objects to be used in expressions containing float data values. The way I have it now, I'm getting an error that says operator float(const Fraction &) must contain 'void', which makes no sense to me. Lines 155 - 173.
// Fractions CLASS // Source: Fraction2012.cpp // Author: Warren H. Knox, Jr. // Date: 11/8/2012 #include <iostream> #include <cstdlib> using namespace std; class Fraction {
I'm trying to compare 2 fractions using operator overloading. The program crashes when this is called;
this is definition: bool operator == (const Fraction& f1, Fraction& f2) { if (f1==f2)return true; else return false; }
this is my calling in the main: Fraction f1, f2; cout<<"Enter in the format: 2/4 or 4/9 "; cout << "enter first fraction: "; f1.Input(); cout << "enter second fraction: "; f2.Input();
Fraction result: result = (f1 == f2);//i think problem lies here. result.Show();
and this is the prototype of the operator: friend bool operator == (const Fraction& f1, Fraction& f2);
I have a class 'A' which is almost perfect for my needs. Class 'B' uses class 'A' I've now designed Class 'C' and Class 'D' and noticed that there is a good chunk of code in class 'B', 'C' and 'D' for using Class 'A' is duplicated. I've separated out this code in specific, standalone functions in each of the classes. Now I'm wondering where this code should go. At the moment, the functions are duplicated in the three calling classes (B, C and D). Placing the functions into class 'A' would break the single responsibility principle. Inheritance to add functionality would likely break both SRP and LSP. The one that seems that it may work is composition.
However, Is designing a complete class just for a few functions over kill?
Would it be valid for classes 'B', 'C' and 'D' to access both the new class 'E' (which would depend on A) and the old class 'A' (which would have to be the same instance as the instance in the new class 'E'), or should the new class 'E' provide sufficient functionality so that Classes B, C and D don't need to access Class A directly? It would seem that its then an incomplete interface of the original object with additional functionality (ie, incompatible) Or should I do it a completely different way?
I am making a game and want to make an updater that grabs the source code from a page on the web. Can this use things that are available to all platforms? It could just be something that grabs the text from the page and executing it (maybe using something like Python's exec() command ?) BTW I'm using mac
this is my code i want to put the part where i have it do multiplication and addition into functions. and then call them so that it can run the addition and multiplication. Heres my code
# include <iostream> using namespace std; int main(){
I'm pretty new to C++ and I'm on Binary Trees in "Jumping into C++"! I've just created a DLL project on Code::Blocks, and I cannot get it to build and run: "You must select a host application to "run" a library..." is the message that I'm getting when I run the main code file. It's had no changes to it (except for a few extra, unnecessary line feeds), and it's the file which Code::Blocks generates on a DLL project.
whats wrong with this code, I'm trying to parse a .js file and replace all the ";" with "; " i.e add a new line after each ";". So I load the file into a char[] buffer then assign a string to this contents of this buffer. Then loop char by char through using an iterator and check for a ";", if found use replace. So int i gets to about 85898 then crashes with unknown error, 'i' should reach about 175653. It does work up till it crashes. And, is this not a simpler way to load a file into a buffer, there is in C.
I have a function that needs to return a "uint8_t" value. However before doing the processing I need to perform a test on the argument to check if it's between expected boundaries. Although this function works it gives (a logical) warning that not always a value is returned although expected. What is the normal way for functions like these where I normally should return e.g. -1 in case the test doesn't succeed and otherwise the uint8_t (t) value?
Code: uint8_t myFunc(int a) { if (a >= 0 && a <= 100) { // Perform actions uint8_t = ... return t; } }
I am using windows 64 bit 2007 , codeblocks and ive tried googling on how to strip all symbols to binary so that the people i send it to cannot read the game files but ive not found anything much... How do i do it on codeblocks..? Code: