C++ :: Output Numbers As 2 Decimal
Feb 11, 2013
My program needs to be adjusted to send out the numbers as 2 decimal , but nothing work.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int
number_ofstyle_American,
number_ofstyle_Modern,
[Code] .....
View 1 Replies
ADVERTISEMENT
Apr 26, 2013
I need to display 0-15 hex numbers[0X00-0x0F] in decimal value...& I'm getting the output but it's not exactly what it should be,below is my code.. [This not the complete code,but main part where the changes are done]
Actual output i should get is for 1v it should generate 0001,for 2v it should generate 0010 and simultaneously till [15v-1111]... But what i'm getting is exactly different to this for eg for 7v,8v&9v the bits generated are 1101,1011,1011 respectively...
[URL] ....
Code:
sbit V1 = P2^0;
sbit V2 = P2^2;
sbit V3 = P2^4;
sbit V4 = P2^6;
#define DAC_table V1,V2,V3,V4
#include <stdio.h>
#include <string.h>
idata unsigned int ptr2tbl ;
[Code] .....
View 2 Replies
View Related
Jun 20, 2013
User enters sentence "The Smiths have two daughters, three sons, two cats and one dog." (The numbers may change depending on what the user chooses to enter. He told us the range would be from zero to nine.) and we have to convert the written numbers within the sentence into actual decimal numbers and print out the new sentence. Ex. The Smiths have 2 daughters, 3 sons...etc.
I have written the following bit of code which reads the string and finds all the "written numbers" but I am not sure how to proceed from there. I am stuck on how to print out the new sentence with the converted numbers as my professor mentioned something about creating the new string using dynamic memory allocation.
Code:
#include <stdio.h>#include <string.h>
int main () {
char A[100];
int length = 0;
int i;
[Code] .....
View 7 Replies
View Related
Mar 28, 2013
I have this simple code here:
Code:
#include <iostream>
int multiply (double x, double y) {
double result = x*y;
return (result);
[Code] ....
I get the answer 5.94 (which is what I'm looking for). I can't work out why the first example is not outputting a decimal number. I have set the variables as a double so I just can't see why this is not working for me.
View 1 Replies
View Related
Jun 22, 2013
I am learning c because I want to get back into programming microcontrollers, which I previously did in assembly. I wanted to make something fairly tight in terms of program memory and RAM to show me an output in binary form. When you are troubleshooting a file register or serial interface when you can see the actual bit values (on a small LCD for a micro-controller) and compare it to a datasheet.
Code:
#include <stdio.h>
#include <math.h>
int main() {
int i;
int decimaltoconvert;
int convertingarray[7];
int convertingarray2[7];
[Code] .....
Also, how might I go about putting that into a function that I could call?
View 6 Replies
View Related
Jul 30, 2014
how I can make my output only have 2 decimal places because I want it to be a monetary value. In my code I used this:
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
which worked well at first because on my command prompt screen the numbers had two decimal places and looked liked this:
Premium for Pol1 is $14101.62
Premium for Pol2 is $14221.16
Premium for Pol3 is $582390.50
Premium for Pol4 is $220384.49
However, I also have the program outputting to a textfile called "output.txt" and when I opened this text file the numbers only had one or no decimal places.
Premium for Pol1 is $14101.6
Premium for Pol2 is $14221.2
Premium for Pol3 is $582391
Premium for Pol4 is $220384
How come the code for two decimal places is working for my output to command prompt but not my output to the text file?
Here is my code.
double ratesmn[86] = {
#include "MaleNonSmoker.txt"
- 1
};
[Code].....
View 2 Replies
View Related
Feb 2, 2015
This program has to convert an unsigned binary number into a decimal number. No matter what binary number I enter, however, it always outputs that the decimal number is 0.
My code is as follows:
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
string binarynumber;
cout << "Enter an unsigned binary number up to 32 bits." << endl;
[Code] ....
And my output:
Enter an unsigned binary number up to 32 bits.
00001111
That number in decimal is 0
The output should have shown the binary number in decimal to be 15, and I cannot find my error.
View 6 Replies
View Related
Apr 19, 2014
event................. red house.............. blue house........... yellow house
Chess ......................12.................... 5....................................8
TableTennis .................. 4.......................... 11.....................17
Basket Ball .................... 6......................... 5......................14
karathe ..........................5........................... 8.........................10
Write a program to input the house name, and the score (as shown in the table) of the sport event obtained by the corresponding house. Then find the total score . You should use nested selection statements.
i) If the user inputs a wrong house name, display the error message "In valid House Name".
ii) Modify the program to handle many data. After calculate and disp ay the total score of the house, the program should display a prompt "Do you need to enter nother house name?".
If the user inputs "y" or "Y", program should ask for the next house name and the scores.
If the user inputs "n" or "N" after entering all three houses, program should terminate by printing the score of the winner.
If the user inputs "n" or "N" and without entering all three houses, program should display an error message "Error in finding the winner" and terminate without printing the ranks.
Note: format the output into two decimal places.
Sample output:
Enter the house name: red house
Enter the score of Chess: 12
Enter the score of Table Tennis:4
Enter the score of Basket Ball:6
Enter the score of karathe 5
Score is: 27 Points
Do you enter another house name? y
Enter the house name: blue house
Enter the score of Chess:5
Enter the score of Table Tennis:ll
Enter the score of Basket Ball:5
Enter the score of karathe 8
Score is: 29 Points
Do you enter another house name? y
Enter the house name: yellow house
Enter the score of Chess:8
Enter the score of Table Tennis: 17
Enter the score of Basket Ball: 14
Enter the score of karathe 10
Score is: 49 Points
Do you enter another house name? n
The winner scored: 49 Points
View 3 Replies
View Related
Jan 29, 2015
Write a C++ application program to accept a signed decimal integer as input and output the equivalent 2s complement version in 16-bit binary. Include a space between every four bits in the output string. The input will only be processed by the application if it falls in the valid range that can be represented in 2s complement format with 16 bits. The range of a decimal number from - to + is -32768 to 32767.
View 3 Replies
View Related
Mar 27, 2013
The code should convert binary numbers to decimal but it doesn't..
Code:
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
[Code] ....
View 4 Replies
View Related
May 16, 2014
Extracting integers from a string is trivial, but I am unable to find a function or code that will extract decimal numbers from a string.
I have a string that looks something like this:
" Asdf 1 1.3825 4.0000 12.0000 1.9133 0.1853 0.9000 1.1359 4.0000 "
Any tips on extracting the numbers (in decimal form) and storing them in a vector?
View 5 Replies
View Related
Apr 25, 2014
This is the question: [URL] .....
Now I have the binary numbers printed out in my code, but I don't know how I can covert them into to decimal.
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main() {
int numberOfDigits;
int numberOfRows;
char flag;
[Code] ....
View 1 Replies
View Related
Oct 11, 2013
So I am trying to write a program that converts roman numerals into decimal numbers. I so far have come up with:
Code:
#include <stdio.h>
#include <ctype.h> // importing the tolowerfunction
//variables
int decimal, total;
char numeral[];
[Code] .....
But each time I compile it, it times out as if it were hitting an infinite loop. I have a feeling that I am not passing an individual character to the roman_to_decimal function but am unsure why.
View 5 Replies
View Related
Sep 24, 2014
Write a program which stores 10 decimal numbers in an array. For these numbers accept input from the users. Once the array is populated do the following:
Display each elements of the array
Display the sum of all the elements of array
View 1 Replies
View Related
Sep 24, 2014
Write a program which stores 10 decimal numbers in an array. For these numbers accept input from the users. Once the array is populated do the followings:
Display each elements of the array
Display the sum of all the elements of array
View 4 Replies
View Related
Sep 13, 2013
Create a program that will ask the user to enter a decimal value (1-999999) then display its corresponding binary numbers. Repeat this process until the value entered is equal to 0. Use the following Function Prototype:
void BinCodes(int value);
Sample Input/Output:
Enter a Decimal: 35
Binary: 100011
Enter a Decimal: 184
Binary: 10111000
Enter a Decimal: 0
View 4 Replies
View Related
May 1, 2014
How to do the problem below using loop?
Input numbers until the user types a 0, then output the product of the non 0 numbers: e
E.g., if the user types 2 4 6 0, the program should output 48
View 3 Replies
View Related
Sep 23, 2014
I am trying to make a program that will convert a list of binary numbers from a file into decimal and print the decimal to the screen. I have no problem doing the conversion, the problem comes up when our teacher wants the input file in a format as such:
3
10110101
11111111
10101010
The first number is supposed to tell the program how many different 8bit strings it is going to have to convert, and then the following lines are those binary numbers.
I am not very experienced with file inputs, and I know how to open files and read lines in.. The problem is, how to say "ok the first line says 3, so now I have to convert the next 3 lines" . I am assuming it is just a simple loop that I am missing....
View 4 Replies
View Related
Apr 26, 2013
I need to write a code in c++ , to input decimal number and the output to be number in Scientific notation with 32 bits .
View 1 Replies
View Related
Dec 12, 2014
I would like to know if there's a way to show at least two numbers in the output instead of just one. For example: instead of showing 4 it shows 04. Its for a console application.
View 3 Replies
View Related
Mar 25, 2014
This is one part of my program, I need a loop that checks through the input(specifically the agent numbers) and then outputs the agent numbers that aren't in the input, from 1 to 20(because there should only be 20 agent).
My input is :
1 3 250.00
2 0 0
15 1 1000.00
3 4 300.00
12 2 500.00
1 2 300.00
3 4 115.00
21 3 400.00
-1 4 250.00
15 1 200.00
9 5 -150.00
18 2 140.00
13 2 550.00
the first numbers are the agent numbers so 1 , 2 ,15 are agent numbers and out output for agents who didnt participate are : 2 , 5 , 6 , 7, 8, 9, 10 , 11 , 14 , 16 , 17 ,19 20
this is the code ive wrote but its not working.
void not_part() {
ins.open(in_file);
int i=0;
int sum=0;
cout<<"AGENTS WHO DID NOT PARTICIPATE IN THE CAMPAIGN"<<endl;
cout<<fixed<<showpoint;
[code].....
View 1 Replies
View Related
Mar 24, 2014
This is one part of my program, I need a loop that checks through the input(specifically the agent numbers) and then outputs the agent numbers that aren't in the input, from 1 to 20(because there should only be 20 agent).
My input is :
1 3 250.00
2 0 0
15 1 1000.00
3 4 300.00
12 2 500.00
1 2 300.00
3 4 115.00
21 3 400.00
-1 4 250.00
15 1 200.00
9 5 -150.00
18 2 140.00
13 2 550.00
the first numbers are the agent numbers so 1 , 2 ,15 are agent numbers and out output for agents who didnt participate are : 2 , 5 , 6 , 7, 8, 9, 10 , 11 , 14 , 16 , 17 ,19 20
This is the code:
void not_part() {
ins.open(in_file);
int i=0;
int sum=0;
cout<<"AGENTS WHO DID NOT PARTICIPATE IN THE CAMPAIGN"<<endl;
cout<<fixed<<showpoint;
[Code] ......
View 11 Replies
View Related
Mar 17, 2015
I am currently writing a program and am having some trouble figuring out how to get the order correct in the output.
Here is my code:
using System;
using System.Collections;
using System.Text;
namespace The_Last_Survivor {
class Program {
static void Main(string[] args) {
[code].....
The output I need to have is:
Actors Count Audition Order
1 1 1
2 1 1 2
2 2 2 1
3 1 1 2 3
3 2 2 1 3
3 3 3 1 2
4 1 1 2 3 4
4 2 2 4 3 1
4 3 3 2 4 1
[code].....
Right now the numbers are just printing in order 1-9 and not changing.
View 7 Replies
View Related
Mar 24, 2014
Why do i keep getting wrong results
Code:
#include "stdafx.h"#include <stdio.h>
#include <string.h>
nt main(void){
char name[40];
int numbers[50];
[Code] .....
View 4 Replies
View Related
Jan 23, 2014
Write a program that reads in ten whole numbers and that output the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once each and the user can enter them in any order.
Your program should not ask the user to enter the positive numbers and the negative numbers separately. Assume the user will type integer numbers.
this is what i got but it wont run saying there is an error
#include<iostream>;
using namespace std;
int main() {
int count=0;
int num;
int positive=0;
int negative=0;
[Code] ....
View 5 Replies
View Related
Apr 6, 2015
I wrote an code for generating an aoutpu of random numbers, but it doesn't gives me back the numbers here is the code:
#include <iostream>
#include <time.h>
#include <cstdlib>
#include <stdio.h>
#include <iomanip>
#include <cmath>
using namespace std;
const int ANZ = 6;
[Code] .....
I cant find the mistake.
View 2 Replies
View Related