C++ :: Equation That Determines The Lowest Possible Cost For Laying Power Line

Apr 9, 2013

I need an equation that determines the lowest possible cost for laying power line.

The variables are as follows:

1. The width of a river
2. The distance a factory is downstream from a station on the other side of the river.
3. The cost for laying line underwater.
4. The cost for laying line on land.

All these variables will be user input each use of program.

View 4 Replies


ADVERTISEMENT

C++ :: Function To Randomly Determines Suit And Value Of A Card

Jul 19, 2013

I'm writing a card game and I'm having trouble getting the first part of it right, which is picking out a random card from the deck and displaying it to screen. So it's supposed to display a different card every time i run the function in the program. The problem is, I keep getting the same output every time "Nine of Hearts".

This is what I have so far,

#include <iostream>
using namespace std;
//declare two string arrays
//one holds the "suit" of the cards, the other hold the "value"
string suit[] = {"Diamonds", "Hearts", "Spades", "Clubs"};
string faceValue[] = {"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ace", "King", "Queen", "Jack"};

[Code] ......

This is the output I keep getting every time I run the program:

Nine of Hearts

This "random selection" function I'm trying to do is meant to work as a means of shuffling the cards in the beginning of every round in the game and displaying only the top card from the deck.

View 1 Replies View Related

C++ :: Determines Whether A Number Which User Inputs Is Prime Or Not

Jan 11, 2015

I am fairly new to C++ and I am trying to write a code that determines whether a number which the user inputs is prime or not. I have the code, but when I run it all it actually does is report odd numbers as prime and even numbers as not prime.

#include <iostream>
using namespace std;
//declaring variables//
int i;
int num;

[Code] ....

View 7 Replies View Related

C/C++ :: Write Program That Determines If String Has All Unique Lowercase

Sep 16, 2014

I am trying to write a program that determines if a string has all unique lowercase letters. However i am unable to understand how to write the code as i am very new to C++ and my professor has given us some tasks to do and has not taught us any C++. i am familiar with the syntax but am not able to understand the tasks properly and able to complete them successfully

#include <iostream>
#include <cctype>
using namespace std;

[Code].....

View 6 Replies View Related

C++ :: Exponential Power Function

Nov 13, 2013

Main is supposed to be sending values to the power function.Write a prototype and function for calculating powers of numbers.This version should have an integer return type and take two integer inputs, for the base and the exponent. It should do the following:

• handle negative bases
• return an error on negative exponents (we’re not doing those yet)
• handle zero exponents

Call your function from a nested loop in main(), which calls the function using every combination of negative, zero and positive numbers for both base and exponent. This will test your function without the user having to input all the data.Any code which calls the library pow() function will lose half of the assignment points.

#include <iostream>
using namespace std;
int power (int, int);
int main() {
int size = 10;
int test[size];
int base;

[code].....

View 1 Replies View Related

C++ :: Compute And Output Power Set

Oct 30, 2013

I am trying to do a compute and output a power set program. The numbers will be input through a file. How to do a power set. Here is my code :

#include <iostream>
#include <fstream>
#include <string>
#include <ostream>
using namespace std;
int main () {
string array[21]; // creates array to hold names

[Code] .....

View 1 Replies View Related

C++ :: Creating Recursive Function That Will Print Out A Number To A Power

Apr 9, 2013

I am trying to create a recursive function that i can call on in order to take a user inputed base and exponent and give final answer this is what i have but im completely lost after this i dont even know how to continue. What i have so far

#include <iostream>
using namespace std;
int Exp(int x,int y){
if(base <= 1 || exp == 0) return 1;
if(exp == 1) return base;
int main(){
int number, exp;

[Code] .....

After i set the base situations im not sure how to get the function to make the function take the base to the exponent recursively.

View 3 Replies View Related

C++ :: Lagrange Interpolation Formula - Substitute Values Into Power

May 7, 2013

I did a function for lagrange interpolation formula. However i`m stuck on how do i substitute values into the power. Here is my code snippet :

for(int i=1;i<getSecretShare+1;i++) {
//calculateValue=getSecret+(10*p)+(2 * pow(p,2));
int storeThreshold=getThreshold;
calculateValue=getSecret+(10*i)+(2 * pow(i,2));
calculateFinalValue=calculateValue % 17 ;
cout<<"the calculated value is "<<calculateFinalValue<<endl;
}

The formula that i want to implement is that a + a1x^1 + a2x^2 + a(t-1) ^t-1

I have gotten the substitution of the x value out. However, i am stuck on how do i calculate the values according to the threshold which the user keys in. For example if the user keys in 3.

It will into account the no. of shares to generate which is for example 5 in this case, then it will then take into account the threshold keyed in , which is 3, i will then calculate using the formula using the no. of shares and also threshold.
if the threshold is 3 and the number of shares to generate is 5. I should have the following:

y(1) = 13 + a1(1)^1 +a2(1)^2
y(2) = 13 + a2(2)^1 +a2(2)^2

the power depends on the threshold which is t-1, 3-1 =2

So I will have to generate two a values based on that and also calculate them according to the power that is dependent on the threshold the first value being to the power of 1 and the 2nd being to the power of 2 if the threshold is 4.

Then I will generate 3 a values and then calculate them :

y(1) = 13 + a1(1)^1 + a2(1)^1 + a3(1)^3

and so on..

View 4 Replies View Related

C++ :: Memory Cost On The Loop Of Menus?

Jun 26, 2014

I have a question on the wasting of the memory on the use of menus. What is the task: I have mainMenu, subMenu1, subMenu2, subMenu3, ... Entry from mainMenu, and chose 1(or 2, 3,..) to subMenu1. If tasks done, go back to the mainMenu.

The Codes:

void mainMenu(){
//input 1-3 by user
switch(choice) //choice is the input

[Code].....

My problem is: the call for mainMenu() in subMenus looks like a recursion, which means the memory would be reallocated again for the called maniMenu. Is that right?

If so, times of the memory space for mainMenu function are required if going back to mainMenu several times from subMenus. But what i wanna just a choice and I dont want to wast the memory.

View 4 Replies View Related

C :: Detect CPU Power Button Press Event In Console Application

Feb 5, 2015

I am using Windows 7 32bit OS and want to detect the CPU power button press event in my console application developing in C language.

I configured the power button setting to "Do Nothing" which is in "Choose what the power button does" options in Control Panel->Hardware and Sound->Power Options. So now i want to detect this power button press event and do some processing in my application then i will initate shut down from application itself. Looking for windows API details which will detect the power button press event.

View 2 Replies View Related

C++ :: Program To Check If User Presses Power Button On Computer

Jun 19, 2014

How you can make a c++ program that checks to see if the user presses the power button on their computer? And if so, how?

View 1 Replies View Related

C++ :: Determine Health Of A Power Transformer - Graphic User Interface?

Nov 27, 2014

I have a program I want to write that determines the health of a power transformer. I know the syntax of all the other code I might have to use but I'm not too sure of how to make it fit into a graphic interface like you see in any other windows program.

View 1 Replies View Related

C# :: How To Manually Control The Temperature Of High Power Leds Using PID Controller

Mar 20, 2015

how to manually control the temperature of High Power Leds using PID controller. I have two GUIs,one reads the temperature from the Led while the second is used to ON/OFF the Leds and at the same time controls the Led brightness using slider control.The GUI that reads the temperature has a PID controller application on it.The output from this controller is what i want to use to increase or decrease the Led brightness which invariable changes the Led temperature.How to go about using this PID controller to control the Led brightness is what i have not been able to grasp well.The slider on the GUI is scaled from 0% to 100%.My thinking is that the output from the controller should be in percentage which will make me to adjust the slider accordingly.My question is that will this type of arrangment produce an output that will efficiently control the Led brightness. how to accomplish that. Attached to this post is a modified code of a tutorial on PID controller which i found on the net. a tutorial on how to develop a graph. i wish to display the Setpoint,Process value and the output value on a graph.

View 2 Replies View Related

C :: Create A Program That Will Calculate A Shipping Cost?

Feb 16, 2015

So im trying to create a program that will calculate a shipping cost. I'm stuck on trying to calculate the actual milage and cost. Example being 1400 miles for a 2lb package would be $2 for every 500miles. so it would cost $6. But Im having trouble getting the program to round up the 1400 to 1500 so it charges the correct amount.

I know there would have to be a way to do this without programming all the conditions.

Also the course has not reached loops yet.

Code:

// This program will calculate the shipping charges.// The shipping rates are based on per 500 miles shipped.
// They are not pro-rated, i.e., 600 miles is the same rate as 900 miles or 1000 miles.
#include <stdio.h>
#include <stdlib.h>

[Code]......

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/C++ :: Declare And Initialize A Pointer To Variable Int Cost

Mar 2, 2014

this question would their be a different process if they asked "declare and initialize a pointer to the variable int cost[N][N]" Here's what I have so far

[#include<stdio.h>
int main() {
int a; // Step 1
int *ptr; // Step 2
a = cost; // Step 3
ptr = &a; // Step 4
return(0);

[Code] .....

View 5 Replies View Related

C++ :: Program To Find Shortest Path Between Vertices Using Matrix Power Multiplications

Feb 24, 2013

given matrix A find shortest path between vertices using matrix power multiplications untill u get nonzero values,use adjacency matrix

View 1 Replies View Related

C/C++ :: Calculate Cost From Wholesale To Final With Percentage Markup

Apr 15, 2014

Program calculates cost from wholesale to final cost with percentage markup!

#include <iostream>
using namespace std;
int calculate_retial(int,int);
int main () {
int wholesale;
int markup;
int cost;

[Code] ....

View 5 Replies View Related

C/C++ :: Calculate Total Cost Given The Tax Values - Getting C2784 Error

Sep 3, 2014

// Purpose: calculate total cost given the tax values

#include <iostream>
#incluse <string>
using namespace std;
int main() {
double purchasePrice, stateTaxAmt, countyTaxAmt, totalCost;
//Display purchase price

[Code] ....

View 2 Replies View Related

C++ ::  Minimum Cost Path Visiting Half The Cells In A Grid?

Mar 11, 2013

I am trying solve this a problem: [URL] .....

In short:
1. Input is an N x N grid with a non-negative integer in each cell.
2. We can move from one cell to any of its adjacent cell in all four directions.
3. The 'cost' needed to move from one cell to another is the positive difference of their values.
4. We have to find the minimum cost such that we can visit atleast half of the cells with that cost;

I am not being able to think of any solution that runs in time O(N2) or better (N2 because of the size of N, any algorithm worse than it will not run within the time limit) for this problem.

So I need a hint on how to solve this problem optimally.

View 2 Replies View Related

C++ :: How To Get The Value Of Variable From Equation

Mar 25, 2013

how to take two variables with values such as a 1; and b 2;. Now you take cout << a + b; and you will get 3, but I want to somehow have a 1; b 2; and c num; then have a + b = c. So what ever I have the user input is for a and be added together will become the value of the c variable.

View 1 Replies View Related

C :: Calculate Cost For Production Of Open Top Cylinders - User Defined Functions

Feb 20, 2013

I have this program I wrote to calculate cost for the production of open top cylinders and how to translate it into user defined functions. Here are the user defined functions I need to use instruct() get_area() comp_area() and print_area_cost() so the program will be in 4 parts.

Code:
#include <stdio.h>
int main()
{double radius,height,cost,single,all;
float surface_area;
int count;
double pi=3.14159265;
printf("Enter the radius of the base in cm^2:

[Code] ......

View 2 Replies View Related

C++ :: Word Counter - Calculate Number Of Letters And Give Total Cost

Nov 4, 2013

I am currently working on an assignment.

#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
char letter;
int count = 0;
double ppl = 0;
double finalCost = ppl * (count - 1);

[Code] ....

I am trying to create a word counter program that asks for the price per letter and then asks for the sentence they are writing. The app should then calculate the number of letters and give the total cost similar to:

You have 40 letters at $3.45 per letter, and your total is $138.00.

Everything compiles fine but when I run it the inputs don't work and it outputs:

You have -1 per letter, and your total cost is $-0.

View 2 Replies View Related

C/C++ :: Parking Garage Cost Calculator Based On Type Of Vehicle And Time

Nov 3, 2014

There are a few functions for this code and I am not very good with functions yet(we just learned about them last week).

//This program will calculate the cost of using a parking garage
//based on the type of vehicle and the time of parking.
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string>
using namespace std;
//define rates

[Code] ...

Error List:

Error1error C2100: illegal indirectionc:userscodydesktopgaragecodegaragecodesource.cpp971GarageCode
Error2error C2100: illegal indirectionc:userscodydesktopgaragecodegaragecodesource.cpp1051GarageCode
Error3error C2561: 'main' : function must return a valuec:userscodydesktopgaragecodegaragecodesource.cpp1161GarageCode

[Code] ....

View 2 Replies View Related

C :: Quadratic Equation - ID Returned 1

Oct 18, 2013

This is my code:

Code:
#include <math.h>
#include <stdio.h>
int main(void) {
float a,b,c,root_1,root_2;
printf("Please enter value a from the quadratic equation

[Code] ......

And I keep getting this error:

Code:
/tmp/ccgtUIun.o: In function `main':
assign345.c:(.text+0xc7): undefined reference to `sqrt'
assign345.c:(.text+0xef): undefined reference to `sqrt'
collect2: ld returned 1 exit status

View 5 Replies View Related

C :: How To Get Values From The User And Add Them To Equation

Oct 30, 2014

I have a small project for school due today but i cant get my head around programming

Ive to create a program where ive to get the values from the user and add them to an equation. I have also to add a selection statement where it will ask for the material being tested which will have its value set in the program.

View 4 Replies View Related







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