C/C++ :: Program For Adding Many Fractions With Sum Notation
Jul 16, 2014
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
",/>;
View 6 Replies
ADVERTISEMENT
Mar 18, 2014
Ii need an output like this...
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <ctype.h>
#include <locale>
using namespace std;
int EquationNum (int Num1, int Den1, int Num2, int Den2);
[Code] ....
View 9 Replies
View Related
Dec 10, 2013
Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following function: a function to convert the time from 24-hour notation to 12-hour notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the choices, function(s) to get the input, and function(s) to display the results. (For 12-hour time notation, your program must display AM or PM.)
Answer:
#include <iostream>
#include <iomanip>
#include <cmath>
[Code]....
It is showing error because may be I was not able to put that if statement inside any function. find out the error sand complete the program with corrected code.
View 2 Replies
View Related
Oct 24, 2013
I need to write a program that can calculate fractions.
View 2 Replies
View Related
Feb 11, 2014
I have to develop script in C to print the alphabets in given notation.
Please check the attachment.
View 4 Replies
View Related
Dec 12, 2014
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 );
}
[code]....
View 7 Replies
View Related
Jul 12, 2012
I have to write a function
struct rNumber add(rNumber a ,rNumber b);
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.
View 5 Replies
View Related
Feb 17, 2013
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.
View 4 Replies
View Related
Jul 30, 2013
I am making a function that finds the sum of two fractions(fractions are arrays of 2 elements). how would I return an array?
int addFrac(int f1[2], int f2[2]){
int num1 = f1[0]; // numerator of fraction 1
int den1 = f1[1]; // denominator of fractions 1
[Code] ......
View 2 Replies
View Related
Aug 1, 2014
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 {
[Code] ....
View 9 Replies
View Related
Jul 25, 2013
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);
View 7 Replies
View Related
Aug 4, 2013
Is there a simple notation to check if a value is within a plus or minus range?
E.g.
//I read a value A. delay(50); //Read value again -calling this value B delay(50);
//Read value again -calling this value C delay(50); //Read value again -calling this value D delay(50);
//Read value again -calling this value E
Check IF first value A is within 5 of the value B and within 5 of value C, etc.
I can think of a few round about ways of doing this but is there any simple "equals to plus or minus" notation? (what I actually want to do is to check a lot more values than this and it will get very complicated with any of my solutions)....
View 4 Replies
View Related
Mar 5, 2014
'm new to programing and I'm trying to get this program to add up a price of coffee to the add on extras such as cinnamon, etc. But once the program runs it doesn't add up the coffee price with the extras and I've been at it for hours...
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
[Code] ......
View 6 Replies
View Related
Dec 2, 2013
I'd like to add a 'command' to my C program. For example if someone types 'get out' it closes the shell and quits. I want the 'get out' command to work like 'exit'. How do I write a code like this
Code:
char entry[15];
scanf("%[^
]", &entry);
if (entry = "get out")
do "exit";
View 14 Replies
View Related
Oct 21, 2014
I am creating a program that allows the user to enter the number of days worked and calculates the amount of money gained by doubling the amount from the previous day, starting with .01 cents. The program works fine except for in day 3, the program adds .01 along with doubling the amount from day 2. Also I must use a List Box.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
[code]....
View 3 Replies
View Related
Mar 12, 2014
I just wrote code that is a program for a relativity calculator. However many of my outputs (because the values tend to be large) end up in scientific notation. Although useful, its not great for the laymen, or nice looking.
How can I change it so that output is not in scientific notation? here is the code:
// This program/converter is designed to find the desired 'real' values using Einstein's theory of relativity
#include<iostream>
#include<math.h>
#include<stdlib.h>
[Code]....
View 1 Replies
View Related
Feb 15, 2015
My program suppose calculate postfix expression.
Ex. 5 4 + 3 10 * + the answer is 39 because if I change it to infix, it's (5 + 4) + (3 * 10)
I need to use vector to compute the value. Here is what I think. First, I save leftmost from the string. If it is a number, I push. If that is a operation, I pop twice and push the result. By doing it until the string is emptied, the vector will only contain the final answer. And here is my code
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
vector<int> stack;
string input;
[Code] .....
When I put 1 1 + or 2 2 +, it showing me a correct answer, but when I put the above example which is 5 4 + 3 10 * +, it shows 30 instead of 39.
View 8 Replies
View Related
Sep 14, 2014
I'm trying to make an infix to postfix notation calculator. The difficult thing is th stack class is custom. It's not to hard to understand, I don't know if the fact that it is that way will not allow me to receive support. The difference is that the pop functions is as such:
stack<char> conversion;
char temp;
conversion.pop(temp);//It receives a parameter and puts the popped element in there.
conversion.peek(temp);//Places the top element in said parameter
not only that... but these are boolean functions. they return true if the operation was completed. So they can be used as conditions.
#include<iostream>
#include<string>
#include<stdio.h>
#include"stack.h"
using namespace std;
int main(void) {
Stack<char> conversion;
string infix,inter,temps;
[Code] .....
The error is that i am mismanaging parenthesis handling and i can't seem to grasp where and how.
An example input is:(35+7)-(9-2)
that input gives me:35 7 + 9 2 ) -
but another input such as :(35+7)/7
outputs as: 35 7 + 7 /. Totally fine.
View 3 Replies
View Related
Jul 15, 2013
double number = 10000000;
int range;//the length of the string result
string result;//holds the number in a string
ostringstream convert; //stream used for the conversion
convert << number;
result = convert.str();
range = result.length();
I'm trying to convert a double to a string and when the number goes to ten million it goes to scientific notation and it shows it in the string. How do I stop it from do that?
View 2 Replies
View Related
Feb 29, 2012
To add my program into the context menu (when the user right click on excel file). I used the following code:
Code:
public static bool AddContextMenuItem(string Extension, string MenuName, string MenuDescription, string MenuCommand)
{
bool ret = false;
RegistryKey rkey = Registry.ClassesRoot.OpenSubKey(Extension);
if (rkey != null)
{
string extstring = rkey.GetValue("").ToString();
[Code] .....
I used the following function to retrieve the excel file path has been rightclick choose to load the program:
Code:
public static void OpenExcelFileWithEasyForm(string filePath)
{
try
{
string excelFilePath = Path.Combine(Path.GetDirectoryName(filePath), string.Format("{0} (EasyForm){1}", Path.GetFileNameWithoutExtension(filePath), Path.GetExtension(filePath)));
[Code] .....
But I still do not load the excel file into my program by selecting the program from ContextMenu (right click on excel file and choose program). Although if select the path to excel file from the program, the data from excel file is loaded into the program.
I'm still missing something at function OpenExcelFileWithEasyForm(). How to complete this function to load the excel file into my program when selecting programs in ContextMenu.
View 1 Replies
View Related
Dec 14, 2013
I want to add a countdown timer to my program so after specific time it go back to the main menu my program is something like vending machine....
View 1 Replies
View Related
Jul 6, 2014
I want to be able to keep on adding a row to my datagrid every time i click a button, the row will hold the text of the text box and the combobox in its individual cells, is there a way to do this without inserting a ridiculous amount of code?
Attached image(s)
View 1 Replies
View Related
Sep 24, 2014
been working on this code til my eyes bled, can not get second operand to work, if i enter 1 2 3 + - it will only return 5 from the addition operand.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
[Code].....
View 5 Replies
View Related
Oct 21, 2014
how i solve this..?
View 1 Replies
View Related
Nov 12, 2013
adding a vowel counter to my recursive program which i completed.
#include < iostream>
#include <cstring>
using namespace std;
void reverseDigits(char num[], char revNum[], int,int);
int main() {
char letters[10] = {' '};
[Code]...
View 4 Replies
View Related
Sep 13, 2013
I have written a star pyramid program, it adds two stars at a time but I want to rewrite the program so the stars double each time.
#include<iostream>
using namespace std;
int main() {
int a = 0, b = 8;
for (int c = 1; c < 10; c++) {
for (int space = b; space > 0; space--)
[Code] ...
View 1 Replies
View Related