C++ :: Double Values On Cout
Mar 6, 2014
Here is code first:
//fp_screen.h
class fp_screen{
public:
double fps;
double xx3;
[Code] .....
fps:1.16922e+006 // this will happen 80%
fps:900 // this is how it should be
if i do cout << "fps:" << (int)screen.fps << endl;
Somethings number is right like 800 or else
put sometimes its 5423423... something.
What is going on here?
View 5 Replies
ADVERTISEMENT
Jun 30, 2013
I m working calculating stuff in files, input and output data, etc..., the question is the following: I output double numbers with:
myFIle << fixed << setprecision(10) << double;
The problem i got is that when a numer is like 193123.2 it prints like 193123.200000..., so finally, ¿how can i print it with any additional 0 that i need?.
View 1 Replies
View Related
Apr 11, 2014
I'm trying to build a new project and i installed some new libraries in it but when i try to compile any code it doesn't give me any value just press any key to continue, i didn't make any files but one and even if i tried to do this simple task it doesn't cout any result:
#include<iostream>
using namespace std;
int main() {
cout <<("ha");
system("pause");
return 0;
}
View 4 Replies
View Related
Mar 24, 2014
I want to compare two double values
double x = 3072.00000000;
double y = 3072.0000000;
when checking with if its not working
if(x==y) it not working
View 1 Replies
View Related
Dec 27, 2013
I have std::vector of players and each player have its own value. The value is of the type double, but the original value are of the "XX.00".
Now what I'm trying to do is to insert a player into this vector. For that I need to find a place and to find a place I need to compare player value.
So lets say I have a player in the vector whose value is 24.00 and I am trying to insert a player whose value is 25.00. To my surprise MSVC 2010 tells me that:
24.0000000000000 == 25.00000000000
I do aware that comparing double type is not going to work like this, but I would expect not to have such big of a difference. ;-)
Why this comparison is true and how to eliminate such thing?
View 3 Replies
View Related
Aug 3, 2014
I'm having a pretty weird problem. I've created an unsigned char array for an image buffer:
buffer_rgb = new unsigned char[_w * _h * 3];
memset(buffer_rgb, 0x0, sizeof(unsigned char)* _w * _h * 3);
And I add pixel color values to it like so:
buffer_rgb[i] = ((unsigned char)(col[0] * 255));
buffer_rgb[i + 1] = ((unsigned char)(col[1] * 255));
buffer_rgb[i + 2] = ((unsigned char)(col[2] * 255));
Where col is a 'vec4' struct with a double[4] with values between 0 and 1 (this is checked and clamped elsewhere, and the output is safely within bounds). This is basically used to store rgb and intensity values.
Now, when I add a constant integer as a pixel value, i.e.:
buffer_rgb[i] = ((unsigned char)255;
Everything works as it should. However, when I use the above code, where col is different for every sample sent to the buffer, the resulting image becomes skewed in a weird way, as if the buffer writing is becoming offset as it goes.
These two images illustrate the problem:
tomsvilans.com/temp/140803_render_skew.png
tomsvilans.com/temp/140803_render_noskew.png
You can see in the 'noskew' image all pixels are the same value, from just using an unchanging int to set them. It seems to work with any value between 0-255 but fails only when this value is pulled from my changing col array.
Whole function is here:
// adds sample to pixel. coordinates must be between (-1,1)
void Frame::addSample(vec4 col, double contrib, double x, double y) {
if (x < -1 || x >= 1 || y < -_aaspect || y >= _aaspect) {
[Code] .....
View 1 Replies
View Related
Nov 4, 2013
I need to write a function that will merge the content of two sorted arrays of type double values. The function should not assume that both its input parameter arrays are the same length.
Here is my program so far - I know there is alot of errors and mistakes:
Code:
#include<stdio.h>
void merge(int firstArray[],int secondArray[],int size) {
int mergedArray[size],i=0,j=0,k=0;
while(i<size||j<size) {
if(i==size) {
[Code]...
View 2 Replies
View Related
Jun 10, 2014
This is what my code looks like
class Transaction{
private:
char type;
double amount;
double balance;
string description;
[Code] .....
This part is what I am having trouble with as this section is not printing anything.
for (int i = 0; i < transactions.size(); i++){
cout << transactions[i].gettype() << " ";
cout << transactions[i].getamount() << " ";
cout << transactions[i].getbalance() << " ";
cout << transactions[i].getdescription() << " ";
}
}
View 2 Replies
View Related
Oct 30, 2013
Other than the theoretical difference between cout and cerr where the former puts values to the monitor and the latter puts values related to errors to the monitor, is there any real difference here? Why not use cout when you want to send anything to monitor? Why use cerr at all?
View 7 Replies
View Related
Sep 7, 2014
Am having a problem with the following program not displaying the cout after the while loop, it doesn't ask if I want to enter another employee but just prompts for the employee payrate again.
#include <iostream>
using namespace std;
int main()
// Parameters: None
// Returns: Zero
// Calls: None
[Code] ....
View 1 Replies
View Related
May 11, 2014
Iam working with arrays and i cant get to the write solution to cout the characters.
the Question is : Write a program that inputs a character string from the user as an input (using cin.get())and store it in myStr[ ] array.Assume that the length of the input string is less than 100 characters and the string may contain lower case, upper case, and/or symbols.The program should then print the number of lower case, upper case, digits, and symbols along with the characters themselves.
my code :
#include <iostream>
#include <string>
#include<iomanip>
using namespace std;
int main() {
int ctr1=0, ctr2=0, i=0, ctr3=0;
[Code] ...
What i have now, how can i cout the uppercase characters and the lower case characters and the symbol characters !
View 3 Replies
View Related
Nov 16, 2013
Finally got to functions. Made a simple one that adds two numbers:
Code: int add(int a, int b){
cout<<"a+b=";
return a+b;
}
It refuses to give an output unless I use cout.
If I just call the function like so: "add(12, 24);", shouldn't it print out a+b=36? It only prints out "a+b=", unless I use "cout<<" ahead of the call.
My simple question is why does it need cout ahead of the call? Shouldn't "return" do its job and print out the number?
View 2 Replies
View Related
Feb 17, 2013
i ran the following code in the latest version of code::blocks and it tells me that the objects cout and cin are not declared in this scope. what is the problem?
I used to use Turbo C++ 3.0 and i had no problem whatsoever with that compiler. But now i am trying to move to code::blocks but it is proving very very hard as all the standards have been changed.
I am a school student and thus, we had been told to practice on Turbo C++ 3.0 and now i am unable to unlearn it. Also, if i use printf in place of cout there is no error but i want to use cout as it is what i am comfortable working with.
#include<fstream>
#include<conio.h>
int main() {
using namespace std;
char name[20];
[Code] ....
Is there some document to which i can refer so as to get the latest C++ standards which is C++0x i believe?
View 7 Replies
View Related
Feb 28, 2013
I am beginner in C++ programming. I having a problem to show the output of all the element i store at a array called total_price. the output become unreadable.
#include <iostream>
using namespace std;
int main () {
float price[1]={0};
int qty;
[Code] ....
View 6 Replies
View Related
Dec 11, 2013
So I want to go from having 0 or 1 to having words like false or true. I did it with an if statement earlier today, but I had to get rid of the whole bool thing. I made the variable just a float. But he requires we use bool. Here is my code:
Car y;
cout << "Initial value for the Car: " << endl;
cout << "Age= " << y.getAge() << " years old. The Price= $" << y.getPrice() << endl;
y.setAge(8);
y.setPrice(12000);
y.setRaceCarStatus(true);
cout << "Modified value for the Car: " << endl;
[Code]...
I commented (//) the if statement that I had earlier. If I set RacecarStatus to True, is cout's 1. The starred (*) line right above the comments is the line that I was required to add. I want to cout the actual word true. The one I had this morning won't work anymore.
View 1 Replies
View Related
Dec 12, 2014
I have more programming before this, but everything else works fine. My else loop has an infinite output. i also want it to output an error message if the value is not an integer and return to the input
cout << "Select number corresponding material for fencing:" << endl;
cout << "wood = 1" << endl;
cout << "stone = 2" << endl;
cout << "aluminium = 3" << endl;
cin >> material;
if (material == 2){
cost = 100 * perimeter;
[code]....
View 7 Replies
View Related
Nov 17, 2014
#include<iostream.h>
#include<conio.h>
main()
[Code]....
I tried to make the output look like this --> ENTER YOUR NAME:Victor Collin ENTER YOUR COURSE:BSComSci
but everytime I entered my name the course went to the next line.How to make the output in the same?
View 7 Replies
View Related
Apr 13, 2013
I'm making a very first program. It's very little more then a simplistic calculator, but i'm having a problem with the cout function. It won't display any text what could the reasons be?
#include <iostream>
#include <string>
#include <sstream>
using namespacestd;
int main () {
do {
int(a);
[Code]...
Oh and i'm aware it's still riddled with numerous problems, I just have been working on the cout thing first.
View 3 Replies
View Related
Aug 18, 2013
I'm building a Console class(i realy need it). and i don't understand how can i build the Write() procedure. Heres the structure:
write(varname1[,varnamex])
how can i convert it to cout?
View 14 Replies
View Related
Nov 11, 2013
Getting error: no operator "<<" matches these operands at line 36.
#include "stdafx.h"
#include <string>
#include <iostream>
#include <ostream>
using namespace std;
struct Date {
[Code] ....
View 8 Replies
View Related
Feb 9, 2015
Im trying to run my program and it works fine until the very end where I want it to read "<name> is a <gender> citizen of <nation>." with the corresponding variables. Here is my work for the time being. Also is there a way to make it where if someone puts a M or m for gender, it will spit out Male instead of just m or M.
#include <iostream>
using namespace std;
int main()
{
char gender;
[Code].....
View 2 Replies
View Related
Mar 20, 2012
So in a nutshell I have to write a program that grabs a random line from a file and exchange the numbers for words from other files to create a poem. The problem I have is that when I go to output the parts of the ntca it gets all jumbled and writes over each other. (See output below)
I saw something about a memory leak, but I couldn't see how that could be happening in this program. It's a basic intro level program for a class and I'm just a little stuck.
Code:
void create_poem(const int poem_lines) // called from main function {
//Peform each for each line
for(int x = 1; x <= poem_lines; x++) {
char begin_line[1000];
[Code] ....
Everything works perfectly except for the output which looks like this :
Code:
A 2 2 1 and 1 3 1 // <-- this is the line before translation
junkcarrnet
As stated, I know everything else works through debugging purposes. Just the overwriting is my only problem.
View 1 Replies
View Related
Dec 15, 2012
I am asp.net C# developer. I decided to tackle C++, so I started today. This is probably something simple I am sure.
Code:
srand(static_cast<unsigned int>(time(0)));
int choice = rand() % NUM_WORDS;
string theWord = WORDS[choice][WORD];
string theHint = WORDS[choice][HINT];
[Code] ....
The error is happening on the last output operator, just before the jumble variable on the last line.The error is:
Code:
Intellisense: no operator"<<" matches these operands
operand types are: std::basic_ostream<char, std::char_traits<char> <<std::string
I understand what its saying, but jumble is a std::string
Here are my preprocessor directives and using statements
Code:
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
View 4 Replies
View Related
May 20, 2013
Why is my program outputting zero for the variable pop?
Code:
#include <iostream>
int main(void){
using namespace std;
//capture data
cout << "Enter the world's population: ";
[Code] ....
It's obviously not std::cout, but I'm thinking its the way I'm operating on long?
View 5 Replies
View Related
Sep 22, 2014
I need to create an overloaded cout that will print the contents of an array. So I can say output << a << endl;
And it will print the contents of the object a... which happens to be an array.
class info:
class List {
public:
List();
bool empty(); //returns true of false if empty
void front(); //makes current position at beginning of list
void end(); //makes current position at the end of list
[Code] ....
I understand this code, I am simply calling the size method from the program, but i don't know how to pass in the array so that i can print it line by line... simple syntax i am sure... but the whole thing is baffling me... I need to be able to call this on any variation of the class, so it cannot be specific to any one array.
View 4 Replies
View Related
May 8, 2012
Using c++11, but I don't think that matters here.
output.displayHeader() must execute before the inherited from ostream (cout) executes streaming data, or bad things happen. It's of course not as simple as in the example below, and I need to make sure displayHeader() is never missed.
I'm thinking I need to override the "<<" operator, having my own function call displayHeader(), then call the base (cout) "<<" operator. What's the proper syntax for doing this?
I can't call displayHeader() in the constructor, and I can't call it right after the object is defined. There are exception case scenarios where displayHeader() must not be called, and other things must happen instead.
I'm aware this will result in many redundant bool comparisons versus the way I'm doing it now, and I'm perfectly OK with that.
Code:
#include <iostream>
using namespace std;
class myOutput : public ostream {
public:
myOutput() : ostream(cout.rdbuf()) {
[Code] ....
View 5 Replies
View Related