C :: Program Doesn't Properly Compute Simple Polynomial

Feb 7, 2014

The program will ask for the user to enter a value for x, then compute the following polynomial: 3x^5 + 2x^4 - 5x^3 - x^2 + 7x - 6.However, when I double check it with my calculator I get a wrong answer for random values of x. To simplify my problem I'm using only integers.

Code:

#include <stdio.h>
int main(void)
{
int x, polynomial;
}

[code]...

View 5 Replies


ADVERTISEMENT

C++ :: Compute The Value Of A Polynomial

Mar 27, 2014

This program is supposed to find the value of a polynomial

with x being the number of terms

a[x] being the coefficients

b[x] being the exponents in each term

j being the variable

for example if

x=4

a[x]=1,2,1,5

b[x]=3,2,1,0

j=2

then the polynomial is (j*j*j)+2(j*j)+j+5

the value will be 23

however the value computed is wrong in the code below

#include <stdio.h>
#include <math.h>
int main()

[Code].....

View 4 Replies View Related

C/C++ :: Simple Polynomial Derivative Calculator

Feb 27, 2014

So I'm trying to make a derivative calculator that can do simple polynomial calculations in a very specific way. If you read the cout line you'll understand rather quickly.

#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
using namespace std;
struct variable {
char Variable,degree,constant;

[Code] ....

I get an error at line 33 and 37 saying error: request for member '_cstr' in 'constant', which is of non-class type 'char'
and the same line with 'degree' instead of constant.

View 2 Replies View Related

C :: Food Calculator Doesn't Calculate - Choice Menus Not Display Properly?

Dec 7, 2013

I'm new to c i've been trying to write code everyday, and recently ive been reading a book and decided to write my own program with what ive learned with it, basicly you get a choice for how many different main courses you would like to have (right now you can only choose 1) and then you can choose which course you would like, it then asks for the amount of guests you would like and calculates how much food you will need to feed the guests. My code compiles but the program doesn't work properly

Code:
#include<stdio.h>

float guests;
float lbs;
int guest_att(guests)
{
puts("how many guests will be attending?");
scanf("%d",& guests);

[Code] .....

and this is how the program runs

Code:
Scotts-MacBook-Pro:learnc scott$ ./wed
how many main course choices will you have?
1

Please make a selection.
1. Chicken
2. Fish
3. Steak
invalid choice

Please make a selection.
1. Chicken
2. Fish
3. Steak
1
how many guests will be attending? 55

You need 0.000000 pounds of of chicken

Please make a selection.
1. Chicken
2. Fish
3. Steak
invalid choice

Please make a selection.
1. Chicken
2. Fish
3. Steak

View 3 Replies View Related

C++ :: Program That Will Calculate Minimal Polynomial?

Apr 20, 2013

I need to make a program that will calculate minimal polynomial of the nxn matrix.

View 1 Replies View Related

C :: Flowchart - Program To Compute Average Of N Numbers

Feb 20, 2015

How can you draw a flow chart that will be used to write a program to compute Average of n numbers?

View 1 Replies View Related

C++ :: Write Program That Uses Function To Compute The Cost?

Nov 1, 2013

Write a program that uses a function to compute the cost of a pizza with given diameter and the number of toppings. Constant will be the cost per toppings and cost per square inch. It will contain a reputable structure as well.

diameter=17
number of toppings=3

//complier directives
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>

[Code].....

View 6 Replies View Related

C++ :: Program To Compute And Print A Billing Statement For Each Patient

Oct 17, 2013

Community Hospital needs a program to compute and print a billing statement for each patient. Charges for each day are as follows:

a. room charges: private (P) room = $125.00; semi-private (S) room = $95.00; or ward (W) = $75.00
b. telephone charge = $1.75
c. television charge = $3.50

Write a program to get data from the keyboard, compute the patient’s bill, and print an appropriate statement. Typical input (nut yours do not have to be identical to this) is the following:

How many days was the room occupied? 5
What type of room? P
Telephone used during the stay? N
Television used during the stay? Y

Keep in mind that the user needs to know that the input can be any integer number of days for the length of stay, either (P, S, or W) for the room type, and either (Y or N) for both telephone and television options.

A statement (which yours MUST be identical to) for the data given follows:

Community Hospital Patient Billing Statement

Number of days in hospital: 5
Type of room: Private
Room charge:$ 625.00
Telephone charge:$ 0.00
Television charge:$ 17.50

TOTAL DUE = $642.50

View 3 Replies View Related

C++ :: Program That Compute Final Average Grades Of Class

Jan 28, 2013

An instructor needs you to write a program that will compute the final average grades in her class. There are 5 students in the class. Each student must take 2 exams and 4 quizzes as part of their final grade. The weight of each toward the final grade is as follows:

Exam 1 – 30%
Exam 2 – 30% Quiz 1 – 10%
Quiz 2 – 10%
Quiz 3 – 10%
Quiz 4 – 10%

You must use arrays to store each students 3 digit ID number, exam scores and quiz scores. A multi-dimensional array is mandatory. Request from the user the information needed then output all of the information as well as the final average grade for each student.

View 1 Replies View Related

C++ :: Program To Compute And Display Charges For Patient Hospital Stay

Dec 6, 2013

Write a program that computes and displays the charges for a patient's hospital stay. First, the program should ask if the patient was admitted as an in-patient or an out-patient. If the patient was an in-patient the following data should be entered:

-Number of Days spent in a Hospital
-The daily rate
-Charges for the hospital services(lab test, etc)
-Hospital medication charges

If the the patient was an out-patient the following data should be entered:

-Charges for Hospital services(lab test, etc)
-Hospital medication charges

The program should use two functions to calculate the total charges. One of the functions should accept arguments for the in patient data, while the other function accepts arguments for out-patient data. Both functions should return the total charges.

I dont know why but the result always gives me 0??? This is what I have.

#include<iostream>
using namespace std;
double in_patient(int Numdays, double dailyRate, double Charge_hospServices, double HospMed_Charge);
double out_patient(double Outcharge_Service, double OuthospMed_Charge);
int main() {

double dailyRate, Charge_hospServices,HospMed_Charge,Outcharge_Service,OuthospMed_Charge;

[Code] .....

View 4 Replies View Related

C/C++ :: Program To Compute Length Of String Entered By User By Class

Sep 30, 2014

I want this program by using only iostream.h & conio.h

View 4 Replies View Related

C++ :: Properly Exiting A Program

Sep 2, 2013

If I were to exit a program, is it okay if I fail to properly destroy whatever structures were allocated?

For instance, if I do this with SDL, there might be obvious consequences like a dead window perhaps. But if I do this with a POD structure, is it okay?

Also, I realize RAII is supposed to fix parts of this but it's not perfect when environments are suddenly cut off with something like exit(1/0);

View 2 Replies View Related

C++ :: User Defined Program - Compute Price Per Square Inch Of Cake Using Overloading

Nov 21, 2014

Create a user-defined program that will compute the price per square inch of a cake using an “overloading”. The cake could be a circle or a square type. In the main function, ask for the price of a circle cake and its diameter, while for the square cake, ask for the price, its length and width. The process must be done inside the different function of each cake. (Note: two sub function for the computation of a circle and a rectangle)

Note that when I made this program something weird happen. After inserting the name, all things follow.

<code>
#include "stdafx.h"
#include <iostream>
using namespace std;
double areaRectangle(int l, int w);
double radiusCircle(int r);

[Cpde] .....

View 4 Replies View Related

C++ :: Program Compiles But Doesn't Run

Apr 28, 2013

My program compiles but doesn't run, Here is the screen shot of debugging

//DynBag.cpp : Implementation File
#include <stdexcept>
#include <iostream>
#include "DynBag.h"

[Code] .....

View 3 Replies View Related

C++ :: Program Doesn't Alphabetize Strings

Jan 18, 2015

I can't seem to get my program to alphabetize a vector string. It displays the names, but not in a sorted order.

void sort_names(vector<string> &nameList) {
int i, minIndex;
string minValue;
int size;
size = nameList.size();

[Code] ....

View 4 Replies View Related

C++ :: Program Doesn't Read The End Of File Sequence

Aug 16, 2014

i have a question, i'm studyng the string library type and i have to write this program :

Code:

std::string word;
while (std::cin >> word) {
std::cout << word << std::endl;
}
why if my input is :

hi my name is ^Z

the output is :

hi
my
name
is

why the program doesn't fall out from the while loop ?

why my program does not recognize my sequence of end of file ?

View 5 Replies View Related

C :: Program Doesn't Print Data From Socket

May 7, 2014

I created a basic socket server, which listensing for incoming udp data. When I run the netcat program, I get a response:

Code:
$ nc -luv 1732
Connection from 10.50.11.12 port 1732 [udp/*] accepted
(?@??8?? ??.?n?5
(?@??8?? ??.?n?5|?>)
(?@??8?? ??.?n?5|?>)
^C |?>)

But with my c program it doesn't give the response. It should say something like "here is the message: " and then give a message.

Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>

[Code] .....

View 2 Replies View Related

C :: Ubuntu Build - Test Program To See If Shared Library Properly Built

May 22, 2013

I have created a shared object in Ubuntu (libMYLIB.so). I am now trying to compile a simple test program (testmylib.c) to see if the shared object is properly built. I am getting an error that the build cannot find the shared object. My build command is:

gcc -lm -l /dir/mylib -lMYLIB.so -o testmylib testmylib.c

where /dir/mylib is where my source and libMYLIB.so reside.

What am I doing wrong?

View 9 Replies View Related

C++ :: Count Function In Program Not Working Properly - Counting Blank Nodes

May 9, 2013

I tested my count funtion. So my count function is not working properly, it should return 5 because 5 words have prefix "tal," but it is giving me 10. It's counting blank nodes.

This is my main.cpp file

int main() {
string word;
cout<<"Enter a word"<<endl;
cin >> word;
string filename;

[Code] .....

View 9 Replies View Related

C++ :: Program Output That Doesn't Wait For Replies But Still Captures Them

Jul 21, 2013

I am trying to write a program that can communicate over a very latent internet connection involving a cellular modem. I have some software packages that handle all the telnet like business and will pipe stdout and stdin to a program I can have it execute.

The problem I am running into is that I have to send about 900 ASCII commands to an instrument to request data but it takes about a second between when a command goes out and when a reply comes back. This will wind up taking a very long time and I am looking to speed it up. All of the commands are independent of the reply so what I need to do is create a program that can send all 900 commands with maybe 10ms break between them and to not wait for a reply. It then needs to read the replies and write them straight to a file.

It seems like this should be achievable in C++ but I only have a very basic understanding of the language and thus am not sure where to start.

I am open to using other languages but thought C++ would be a reasonably good start so I can distribute the program to my coworkers. All of our work machines are Windows but if there is a simpler solution from Linux, I should be able to work something out. I'm just trying to avoid complication.

View 5 Replies View Related

C++ :: Program Only Accept Integer From 0-10 But Doesn't Show The Factorial

Feb 28, 2013

#include<iostream>
using namespace std;
int main() {
int a[9],x,f=1;
cout<<"Please enter an integer [0-10 only] : ";

[Code] ....

View 3 Replies View Related

C++ :: Sort Players In Descending Order On The Basis Of Score - Program Not Working Properly

Feb 11, 2015

#include <iostream.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

class Player {
private:
char name[20];
int score;

[Code] .....

View 5 Replies View Related

C++ :: Program That Asks User For Numbers And Adds Odd Ones Doesn't Work

Nov 12, 2014

Title is self-explanatory.

Code:
#include <iostream>
using namespace std;
int main ( ) {
float number;
float sum;
float divi;
while(number != -1) {

[Code] .....

View 5 Replies View Related

Visual C++ :: Program Doesn't Accept Input Values True?

Nov 1, 2014

I am making a program which is going to print out a head image according to the input values entered by the user. Here is the code:

Code:
#include <iostream>
#include <string>
using namespace std;
void Sides()
// draws the sides to take proportion

[Code] .....

At first i tried to work program like:

Code:
cout << "plase enter which way you want to print out the head, with parted hair or bald." << endl;
cin >> headstyle;
if (headstyle != "bald" || headstyle != "parted hair" )

But it also had given the same mistake. The program compiles BUT; even if I put in the values bald or parted hair the program prints out "wrong input" then exits.

View 2 Replies View Related

C++ :: Copy And Paste Function From Other Source Program Doesn't Wait For Input

Nov 27, 2013

I'm working on a project that requires to make modifications to certain functions. So, I'll copy and paste the function to a new source code so I'm just working on the function with the entire program running. When I run the function by itself, it works fine. But when I copy and paste the function back to it's spot, the program doesn't wait for input at the cin.getline & it did wait when I ran just the function by itself. I'm using Dev C++ if that makes a difference.

View 2 Replies View Related

C/C++ :: Program To Compute Students Grades From File And Write Them To File?

Aug 31, 2014

We have to write a program that reads an input file containing data in the form:

Martha J, 80, 90, 90, 100, 89, 99, 85
Anna Smith, 65, 72, 77, 68, 62, 70, 65
Bill Gates, 60, 54, 89, 62, 65, 60, 50
...etc...

and then use that information to determine their letter grade and write that information to a .txt file. I have been able to successfully pass that information to a function to determine their letter grade and have been able to successfully compute their letter grade. However, I can get this information to successfully post within the *computeGrade () function. Yet, I don't know how to pass this information back to the main() on a student by student basis so that I can open a new .txt file and write just their name and letter grade to it.

Another issue I'm having is when it comes to computing the averages of the class. Each score is either a quiz (there are 4), a midterm (there are 2) or a final (there is 1). I'm a little stuck on how to pass say all of the quiz 1 grades as one entity to the function averagesminmax(). Is there a way to compile each of the grades for a specific quiz or midterm as one array and pass that to the function to then do the computation. Also we need the min and max so again from compiling the grades of a particular quiz or exam together as one.

Here's the code that I have so far.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
const char *computeGrade();
int averagesminmax();
int main() {
char fName[20];
char lName[20];

[code]....

Do I need to re-read the input file and assign them to different variables?

Here's a sample of the output so far:

Enter input .txt file name
Graded
Thui Bhu, 91, A
Ariana B. Smith, 96, A
Emily Gonzales, 83, B
Jennifer L, 89, B
Maria Jones, 67, D
Bill Gates, 55, F
Escobar Morris, 78, C
Anne Latner, 88, B
Program ended with exit code: 0

Also in my output file, the only thing that it prints will be the first name of whatever the last student in the input file list is.

View 2 Replies View Related







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