Visual C++ :: Rounding A Number Multiple Of Another

Jul 23, 2013

How would I be able to round a number in multiples of another...

Let's say width is 150
And multiple to be 64...
I want 150 to become 128...
if it was 160 to become 192...

The width number will change and I want to covert it in multiples of the other number example 64... The minimum value will always be the multiple number used...

View 7 Replies


ADVERTISEMENT

C :: How To Use Rounding Function

Jan 16, 2014

I want to round to the 2nd digit in a float. Such as 1.85458 to 1.85. How would i go about doing this. I currently keep rounding to the closest integer so the above would round to 2.

Code:
#include <stdio.h>
#include <math.h>
int main(void){
float n;

[Code] ....

View 4 Replies View Related

C :: Rounding Function Not Working

Oct 12, 2013

Why the roundf function is not successfully rounding my numbers.

Code:
#include <stdio.h>
#include <math.h>
//function declarations
void CelToFah (int ctemp, int ftemp);

[Code]....

it produces a correct number when called, but it is not a rounded number, the roundf((float)cel) does nothing. I get the same number with and without it.

View 6 Replies View Related

C :: Rounding To The Nearest Cent?

Feb 4, 2014

I'm having trouble with rounding to the nearest cent in this program. It's the only thing that i need. The result i need is just off by one cent. I tried multiplying the interest amount by 100 and adding .5 then dividing all that by 100 but that just made it worse. Here's the code:

Code:
#include <stdio.h>
int main()
{
int count=0;

[Code]....

View 6 Replies View Related

C :: Rounding Of Numbers Using Int Identifier

Apr 23, 2013

I have an assignment for uni which requires the program to ask the user to input a number in for a variable to use in later equations. The assignment specifies that if the number that is input into the program is not an interger that it needs to be rounded UP to the nearest interger. e.g. 2.5 = 3, 5.00001 = 6 etc. i have identified this variable using "int" which i know makes it an interger however it also always rounds the number DOWN to the nearest interger. I was just wondering what the best way to approach this problem was. The only idea i have is to put + 0.99999 at the end of this variable when it is worked out so that if it is not a whole number it will be raised above the next interger and then rounded down however this will not work if there is too many decimal places.

View 6 Replies View Related

C++ :: Rounding To Nearest Half?

Mar 9, 2014

How do I round to the nearest half integer?

Example;
0 to 0.2 = 0
0.3 to 0.5 = 0.5
0.6-0.9 = 1

What's the formula for C++?

I found a way to do it in math but I want to know what I'd have to put in C++. It's (x*2+.5)remove decimal numbers and divide by 2. What do I put in place of "remove decimal"?

For ex; x = 8.4 using (x*2+.5)remove decimal then divide by 2.
8.4 * 2 = 16.8
16.8 + .5 = 17.3
17.3 - decimal = 17
17/2 = 8.5

I want to do something like;

cout << " Half number: << (x*2+.5)remove decimal/2 << endl;

What would I have to put in place of "remove decimal"?

View 4 Replies View Related

C++ :: Rounding And Converting To Integer?

Oct 4, 2014

Ok so I'm in a programming 1 class working with c++. I have the following assignment:

Write a C++ program that:
asks for and accepts the Percentage earned with as a double (i.e. 75.45)
rounds it to an integer (>= .5 rounds up, <.5 rounds down.)
prints the original Percentage and the corresponding Grade and Points exactly as shown below.
prints an error message for any input that is less than 0 or greater than 100.

For example, if user enters 89.4, the program prints out:
Percentage: 89.4% Grade: B Points: 3.00
You must use an if-else statement to do this in your program.
Use fixed and precision output manipulators (see Ch. 3) to display the values with the exact precision shown above.

IMPORTANT:
Each if statement condition should contain only one comparison! read this again
This means code that is similar to this is NOT okay:  if (Percentage >= 80.00 && Percentage <90.00)
This code is not acceptable because the if statement condition above has two comparisons.
(Hint: If you order your if-else chain statements correctly, you will only need one comparison in each.)

I have the program working, but I'm pretty sure I'm not rounding how my professor would like it to. This is my code:

#include <iostream>
#include <cmath>
#include <iomanip>

[Code].....

So my issue here is the rounding, and then theres the converting the double percetnage to an integer. In my next assignment I have to write the program with a switch statement.

View 3 Replies View Related

C++ :: Rounding Numbers To Hundreds?

Jul 18, 2013

I have made a random number generator to create a number between 1000 and 9000, but I always get numbers with many 10s and units. I want to round them 100s.

Is there any way to do this?

View 4 Replies View Related

C Sharp :: Rounding Up To Nearest 100

Jul 28, 2012

Rounding a numerical figure up to the nearest hundred. E.G.:

256 >> 300
654 >> 700
15 >> 100

I would like to know the formula to enter into Visual Basic 2008. I'm making a calculator Program, and i need a function that rounds up to the nearest 100...

View 5 Replies View Related

C++ :: Dice Simulator - Floats Rounding Up

Oct 28, 2013

I made this dice simulator which basically throws the dice 1 million times and outputs the frequency and percentage average for each side (1 to 6).

Everything is working fine, except my averages (floats) seem to be rounding up, causing 4% being "unassigned" at the end of the million rolls. I'm outputting with a setprecision of 2, but I only get 0's and no fractional numbers.

View 5 Replies View Related

C :: Function That Tests If A Number Is A Multiple Of Another

Oct 10, 2013

How would I write a function that determines if a number is a multiple of another number.ex. (is 147 a multiple of 7?)

View 5 Replies View Related

C++ :: Getting Multiple Objects To Move Randomly At A Designated Number Of Intervals

Jan 9, 2015

I have a piece of code which gets multiple objects to move randomly at a designated number of intervals. I want to create a function which calculates the distance between each pair of points after that number of steps. so the distance between object 1 and object 2, object 1 and object 3, ..., object 1 and object N. then object 2 and object 3, object 2 and object 4, ..., object 2 and object N. then then object 3 and object 4, object 3 and object 5, ..., object 3 and object N and so on until the distance between all the pairs of points have been calculated.

#include <ctime>
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<fstream>
#include<vector>

using namespace std;

double dist(int a, int b);
int X(int x1, int x2);
int Y(int y1, int y1);

[Code] ....

View 4 Replies View Related

Visual C++ :: Multiple Selections For Uploading

Jul 13, 2013

How do you select multiple folders and upload them. Search recursively? I cant find any code or examples.

View 2 Replies View Related

Visual C++ :: Sum Multiple Group To Find The Max

Dec 17, 2013

How to sum groups in C++? I have a class with 2 attributes (Group and Price). I need to find the group with the highest amount. I can find the max when it comes to finding a set of individual numbers but not when a group is required. For Ex:

Group A64
Group A48
Group A18
Group B49
Group B36
Group C64
Group C75
Group C87
Group C72

The group with the highest amount is GROUP C

View 14 Replies View Related

Visual C++ :: Macro With Multiple Parameters

Oct 22, 2014

In the following example, SET_DARKENING_PARAMETERS_0 is a fairly simple macro which accepts 9 parameters. The first one is called driver and the other 8 are all ints. Basically, the 8 x ints get assigned to the first 8 elements of an array which is owned by driver. I can call the macro successfully if I do this:-

Code: SET_DARKENING_PARAMETERS_0 ( some_driver, 500, 400, 1000, 275, 1667, 275, 2333, 0 );

But in the actual code I'm trying to compile, the 8 x ints are themselves encoded into a secondary macro like this:-

Code: #define CONFIG_OPTION_DARKENING_PARAMETERS 500, 400, 1000, 275, 1667, 275, 2333, 0

So the actual code (to call SET_DARKENING_PARAMETERS_0) looks like this:-

Code: SET_DARKENING_PARAMETERS_0 ( some_driver, CONFIG_OPTION_DARKENING_PARAMETERS );

But the two combined macros won't compile with VC8. Basically, I get warning #C4003 (not enough parameters for macro 'SET_DARKENING_PARAMETERS_0') followed by a load of syntax errors. However, the code (allegedly) compiles with gcc.

I'm wondering if macro CONFIG_OPTION_DARKENING_PARAMETERS might be getting truncated to just 500, (with the following parameters getting ignored)?

View 5 Replies View Related

Visual C++ :: CFileDialog Multiple Selection Limit?

Apr 30, 2013

In my attempt to capture multiple files using CFileDialog I discovered that there is a limit on the number of characters in the file name buffer. [URL]

I have used this code to get the file names and it works fine up to the point where the buffer is full. NB: m_vcsPathnames and m_vcsFilenames are std::vector<CString> types.

Code:
// get a list of the files to process
wchar_t szFilters[]= _T("All Files (*.*)|*.*||");
// Create an Open dialog; the default file name extension "*.*"
CFileDialog fileDlg(TRUE, _T(""), _T("*.*"),
OFN_FILEMUSTEXIST| OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilters, this);
m_vcsPathnames.resize(0);

[code]....

Is there any possible work around for this limitation, other than completely writing my own CFileDialogExx class ?

View 6 Replies View Related

Visual C++ :: Draw Multiple Lines And Move Them On Screen

Jul 28, 2013

I am writing a pure C based win32 applications. I have drawn line. Now i want to translate that line, move the line whereved user wants to move on screen. Then again I drawn another line, I am drawing multiple lines.

I have created rectangle region for each line and trying to move the line.

When I move the 2nd line over the 1st line on screen the 1st line is getting wiped out. Because I am InvalidateRect() of the rect for the line being moved, so when that rectangle is crossing the other line then the other line is getting removed from the screen.

How can I rectify it. How can I have all the lined being on the screen and moved according to the user's wish. The code should be pure C and win32 no MFC.

View 4 Replies View Related

Visual C++ :: Floating CDialogbar On Multiple Screen Environment

Jul 11, 2014

I have an problem with a CDialogbar if my app runs on a system with two screens (side by side). I can not resize it while the CDialogbar is in floating state on the second screen.

I figured out that the problem is the mfc-function CDockContext::Stretch().

It limits the CDialogbar to the primary screen (using ::GetDesktopWindow() to verify the position).

What can I do?

View 2 Replies View Related

Visual C++ :: Finding Items (strings) In Multiple Lists

Mar 12, 2013

Im working on a script compiler and i need to handle different types of data. Actually different categories of items.

Let's say i have two categories: cat's and bird's. They are different and stored in different lists. And let's say there is a simple command: GIVE_FOOD_TO(animal_type, food_type) Animal type here can be either from birds category or cat's category.

And also let's say user gives command: GIVE_FOOD_TO(cat1, fish)
and also for example: GIVE_FOOD_TO(bird1, birdfood)

Variable names could be anything, but im storing each variable name in std::map so later i can figure out with what animal current command is used.

When im parsing the script then i must know if user supplied either cat or bird. If i just would have cat's or bird's category then i would have only 2 lists and not a big problem to loop through either cats list or birds list and find out in what list the "cat1" is or in what particular list the "bird1" is. It would be in one or another.

But i have a lot of categories and looping through all of these lists (or std::maps) is slow and doesn't seem like a good. Just to find out in what list it's stored. I can't rely on variable names, they could be anything.

Big picture atm:

1) I have one BIG box which stores all of the categories

2) When i need to find out to which category the variable (animal_type) point's to i must get it quickly, dunno, std::map in std::map or something?

What i need basically is: I have different lists (each one is just a category for either birds or cats in this example) And when i have variable name, i must find out quickly in what particular category this item is stored. So i can work with it.

View 4 Replies View Related

Visual C++ :: Winsock - Accepting Multiple Clients On A Server?

Jun 16, 2013

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.

Code:
#include <iostream>
#include <winsock2.h>
#include <vector>
#include <process.h>
#include "Included/pthread.h"
#define MAX_THREADS 5
bool gamerunning = true;

[Code] ....

I'm having troubles allowing more than one client to play on the server.

View 2 Replies View Related

Visual C++ :: Can't Make Double-buffered Painting With Multiple Monitors

Sep 19, 2012

I'm trying to remake my Windows screensaver written with C++ and WinAPIs to work on multiple monitors. I found this article that gives the basics. But when I implement it in my own code, I get a weird result. Take a look at this code:

Code:
case WM_PAINT: {
PAINTSTRUCT ps = {0};
HDC hdcE = BeginPaint(hWnd, &ps );
EnumDisplayMonitors(hdcE, NULL, MyPaintEnumProc, 0);
EndPaint(hWnd, &ps);

[code]....

Painting always works on a primary monitor. But when I paint to the secondary monitor, I can only paint directly to its DC. When I use double-buffering technique (with DIRECT_PAINT pre-processor directive commented out) I only get a black screen on a secondary monitor when it should've been red.

First one with direct painting that works:

and then the one that doesn't, with double-buffering technique:

View 12 Replies View Related

Visual C++ :: Multiple Dialogs Supported In One Derived CDialog Class?

Apr 14, 2014

In my class:

Code:
class SettingsDialog : public CDialogEx

I have:

Code:
enum { IDD = IDD_SETTINGS_DIALOG };

I have a very similar dialog called IDD_SETTINGS2_DIALOG with all the exact same variables. Is it possible to conditionally load either of those dialogs in that class through a variable pass into the constructor? If so, how do I edit that enum type to add both?

View 2 Replies View Related

Visual C++ :: How To Use CListCtrl For Show Multiple DialogBoxs Like Items In Icon View

Jan 15, 2014

i can write a mfc program to make a Thumbnail view with image but can not this when change image with CDialogBox.

Thumbnail view with image(chart) like this:

for (int i=0;i<10;i++) {
CChartContainer *cc = new CChartContainer();
if(cc->m_frmWin->Create(_T(""),
WS_CHILD|WS_VISIBLE|SS_BITMAP, rc,
this,idDyn)) {
}
}

how can i write mfc program to make a Thumbnail view of CDialogBoxs?

do i can use CListCtrl for show multiple DialogBoxs?

View 13 Replies View Related

Visual C++ :: Application That Process Multiple Files Through Command Prompt Call

Dec 22, 2012

I am making an application that processes multiple files (typically > 500) through a command prompt call. The way I start the command prompt app is by looping using a call to CreateProcess for each file that is to be processed. It works fine, except that I somehow loose 'connection' to my app so that

1: Windows says that the app. is 'Not Responding'
2: The Cprogress bar in my app is not updated before all files have been processed, even though there is a CreateProcess call and a Cprogress.StepIt() from the app for each file that needs processing.

I somehow suspect that the CPU gets swamped... I do not want that Windows starts to say that my app is 'not responding' and I want my Cprogress dialog bar to update according to the number of files that are progressed through.

I wonder if multithreading is the OK way to go instead of just kicking of series of CreateProcess calls? Maybe my CreateProcess is not ending correctly? It seems as if my app is 'not regaining control' before very late. The app never crashes though.

My CreateProcess code is listed below, maybe there can be a problem with it, or maybe I should do things in a different way? My app basicaly works as it never crashes, but with above mentioned problems it is NOT a pro solution...

void CMultiFilerDlg::ProcessFile(CString pdfFile) {
int i=0;
DWORD ProcID;
// Open file in text mode:
STARTUPINFO si;
PROCESS_INFORMATION pi;
char cmdArgs[2052];

[Code] .....

View 6 Replies View Related

C# :: Multiple Desktop Display (Multiple Explorer Windows)

Jul 31, 2014

I want to develop an application which can host multiple views of explorer (window), where as each window is totally separate from others. So that I can have multiple desktop views through my single explorer. Any built in feature in .NET ?

View 11 Replies View Related

C/C++ :: How To Make Multiple Subroutine And Return Multiple Arrays

Aug 17, 2014

how to make subroutines and return multiple arrays.Before that, i wrote my program on matlab. could my program to be structured as following?

<header>
initial value of program;
subroutine1() {
calculating the first work;
return 2 or 3 arrays;

[code].....

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved