C++ :: Specifying And Multiplying Two Variables
Feb 23, 2014
I'm very new to C++ so I've been trying to run through some code examples to begin to learn basic structures and syntax, but I've recently run into a problem using examples from the 7th ed. of Sams Teach Yourself C++. I'm using the code provided within one of the examples that allows you to specify and multiply two variables, but when I compile and run the executable the final output seems to only show the first variable and b/c of this the multiplication operation does not work.
Here is a my example code:
Code:
#include <iostream>
using namespace std;
int main() {
cout << "This program will multiply two numbers" << endl;
[Code] ....
View 3 Replies
ADVERTISEMENT
Jun 4, 2013
So I have this program to calculate the types of meat, I have fixed the system errors but the actual program when I run it comes up with <null>
Code:
#include <stdio.h>
#include <stdlib.h>
#define beef 1 /* multiplication factor of beef*/
#define chicken 1.5 /*factor of chicken*/
[Code] .....
View 2 Replies
View Related
Apr 19, 2014
#include <iostream>
#include <cstdlib>
using namespace std;
[Code]....
I am trying to initialize int x[] = {10, 100, 1000, 10000} into a loop and give me four different numbers for something. I was trying to get creative and just do
myArr[j] = j * 10; with (int j = 1; j < 10000; j++) ,
But that doesn't work. It still gives me an output of 10 11 12... How to make an array punch through a loop and give me
10 Press any key to continue...
100 Press any key to continue...
1000 Press any key to continue...
10000 Press any key to continue....
I'm thinking I must set the for loop to < 10000.1 or < 10001 to output the final value in the array.
View 3 Replies
View Related
Jun 3, 2013
Trying to multiply to matrixes using the following algorithm,
Code:
ABrec(A,B)
n=A.rows; //n must be multiple of 2
C is a new n*n matrix.
if(n==1)
C[0][0]=A[0][0]*B[0][0];
[Code] ....
but the code doesn't work !!!
View 4 Replies
View Related
Nov 16, 2013
I have an array as such and need to multiply all the values of it by each other and put that as a variable.
//for example
int array1[100]
//assume i have already input the values of each element properly up to, say, element 4
//I need to now multiply all of those values together. I think I need the size of the array to control what it multiplies (I know how to find size) ....
View 4 Replies
View Related
May 1, 2014
we have to make a Invoice class which has a function called computeInvoiceAmount() which multiplies the price and the quantitiy which are private member of the class.
double computeInvoiceAmount(){
return quantity * pricePerItem;
}
This is my function, but if i compile it i get the following error:
"Invoice.cpp:53:11: error: "quantity" was not declared in this scope" and "Invoice.cpp:53:22: error: "pricePerItem" was not declared in this scope"
I tried it with the get functions but i get the same error.
Full code is here: [URL]
View 1 Replies
View Related
May 14, 2012
Two different matrices will be read from text files (input1.txt, input2.txt) and they will be stored in two dimensional arrays (matrix1, matrix2) and one dimensional arrays (array1, array2). Our aim is to obtain the matrix multiplication using two dimensional and one dimensional arrays.
You are asked to write the main and the following functions. The definitions of the functions are given in the skeleton code.
int read_file(ifstream& in_file, int &row, int &col, double *array, double **matrix)
int write_file(ofstream& out_file, int row, int col, double **matrix)
void print_matrix(double **matrix, int row, int col)
void print_array(double *array, int row, int col)
void multip(double **matrix1, double **matrix2, double **result, int k, int m, int n)
void multip_array(double *array1, double *array2, double *array_result, int k, int m, int n)
You are going to obtain the input and output files as command line arguments
input1.txt :
3 4
2 3 4 5
1 3 5 4
0 4 4 7
The first element in the first line represents the number of rows (3) and the second element represents the number of columns (4) of the matrix (the result file will have the same format).
likewise;
input2.txt :
4 5
1 2 3 4 5
2 9 43 44 21
32 32 32 43 54
1 3 3 4 5
thats my homework and here is the code i wrote from the sceleton code they gave me :
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int read_file(ifstream& in_file, int &row, int &col,/* double *array,*/ double **matrix)
[Code] ....
I didn't understand the array part but even when i exclude the array part i get the program has stopped working message. My os is windows7 ultimate with mingw installed and i compile the program using g++ command in cmd with the arguments input.txt input2.txt resultt.txt
View 1 Replies
View Related
Sep 11, 2014
I have code the following but result is not ok.
int main()
{
int i,j,m;
m = 0;
[Code].....
View 3 Replies
View Related
Mar 3, 2013
I am having a bit of difficulty with implementing an object oriented program that uses both linked lists and operator overloading. The program calls for adding and multiplying polynomials together, with each single polynomial being represented as a node of a linked list (which is further a data member of an object of a class I have defined to implement this program). For example:
polynomial A will be: 3x^4 // 1 node of a linked list
polynomial B will be: 5x^2 // 1 node of a linked list
polynomial C will be blank for the time being. // empty list
Now, I need to use operator overloading so that this following line of code can be implemented:
C = A + B;
C should now be: 3x^4 + 5x^2.
The checklist of which parts of my code that work:
constructor works;
copy constructor works;
destructor works;
operator= works;
print function needs work but i can worry about that later;
operator* work on later
Here is my code:
#include <iostream>
using namespace std;
struct termNode {
int exp; // exponent
int coef; // coefficient
termNode * next;
[Code] ....
For the time being I need to add multiple nodes together (with the result being in descending order). So for example:
polyType a(2,3), b(4,5), c(6,7), d;
d = a + b + c;
d.print(); // should print out 7x^6 + 5x^4 + 3x^2, but it will only print out: 3x^2 + 7x^6
View 5 Replies
View Related
Nov 11, 2013
I am suppose to find voltage by multiplying a resistance array and a current array by using a function and pointers. This is what I have so far:
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <iomanip>
[Code] ....
View 1 Replies
View Related
Aug 27, 2014
Having error . I multiplied 0 by -4 and my result is -0 instead of 0. I tried to change the data type put It won't work. This is my code:
#include <iostream>
int main () {
double b, c;
std::cout<<"b: ";
std::cin>>b;
std::cout<<"c: ";
std::cin>>c;
std::cout<<b*c<<std::endl;
return 0;
}
View 2 Replies
View Related
Nov 19, 2013
So here is what i need i need a way i can add 3 variables one after the other example:
int a = 1;
int b = 2;
int c = 3;
//Here comes my problem
int d = a + b + c;
When I write it like thet d = 6 ,
but I need it to be 123,
View 4 Replies
View Related
Mar 19, 2013
I am just a beginner in c++..I am making a program on a physics formula PV=nRT(this is formula of ideal gas equation)i have build the program and it run excellently but i want to improve this i am using a condition p==0 because i want to find 'p' but the problem is every time i run the program i have to input p=0 in the screen but i want the program to skip "p" ( take automatically "p" as 0 when i press enter and got to another varibles)
#include <iostream>
#include <cmath>
using namespace std;
int main()
[code].....
View 11 Replies
View Related
Jul 8, 2014
How are map variables initialized?
PLEASE EXPLAIN THE FOLLOWING CODE TO ME?
// accessing mapped values
#include <iostream>
#include <map>
#include <string>
int main () {
std::map<std::string, int> mymap;
[Code]...
View 2 Replies
View Related
Jun 19, 2013
I have First derivative function implemented in C++. More details [URL] ...
In programming, I'm dealing with a lot of variables. x, y, z & x', y', z' & x'', y'', z'' These are only for one device. The problem is how can I deal with velocities and accelerations the way I did with positions? This is the code
while (1) {
/* Perform a synchronous call to copy the most current device state.
This synchronous scheduler call ensures that the device state is obtained in a thread-safe manner. */
hdScheduleSynchronous(copyDeviceDataCallback, ¤tData, HD_MIN_SCHEDULER_PRIORITY);
x_Position[2] = currentData.m_devicePosition[0];
x_Position[3] = currentData.m_devicePosition[0];
x_Position[4] = currentData.m_devicePosition[0];
[Code] ....
I've tried to create x_Velocity[5] and
x_Position[2] = currentData.m_devicePosition[0];
x_Position[3] = currentData.m_devicePosition[0];
x_Position[4] = currentData.m_devicePosition[0];
[Code] ....
I'm trying also to store x_Velocity in vector. Every time I deal with whether array or vector, the first two points of x position are affected because I'm calling the function for the velocity.
View 8 Replies
View Related
Feb 6, 2013
Suppose x, y, and z are int variables. What value is assigned to each of these variables after the last statement executes?
x = 4; y = 11;
z = y - 2 * x;
x = z + y;
y = x + 5 * z;
w = x - y + 2 * z;
x = y + w - x;
-w;
View 3 Replies
View Related
May 26, 2014
So I am trying to develop a sort of 2d spacesim engine for creating games in C++. The project uses SFML for graphics, and I am currently trying to compile it on Linux using g++.
The main issue that I am wrestling with is that of simulation objects having their position, velocity, and rotation variables constantly getting set to NaN for reasons that are beyond me. The behaviour is not consistent, and occasionally will occur or not occur without any discernible pattern.
The github repo for the code is here: [URL] ....
I understand that NaN values can spread easily by operations on one another, but I cant seem to figure out where the initial issue is occurring here.
View 2 Replies
View Related
Mar 6, 2015
I'm trying to use two variables for two different functions.
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
[Code].....
Every time screen2() runs it always outputs "Numbers entered were 0 and 0". I want the numbers that were entered in by the user in screen1() to be displayed.
View 2 Replies
View Related
Feb 23, 2014
im creating an address book. One address book contains a ListBox, New User button, Edit User and Remove User button. The first form is suppose to allow you to view the users you've created on the ListBox and you can decide whether you want to remove it, create a new one or simply edit the user. Now The second form simply contains labels and textbox along with a save button. I'm having a bit of issue figuring out the ListBox. I want to be able to create a user and have the user be posted on the ListBox. I read that i must instantiate listbox then simply add it. Now on my form2 i have a for loop that loops through an Array of String were all the users will be created on. How can i call that array of string on to the form1?
Form 1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[code].....
EDIT:I just figured out that to call a variable from one form to another you simply instantiate the form then simply call it. PS. must be set to public:
ListBox1 createUser = new ListBox1();
createUser.userString[0];
why doesnt it show the windows when i run without debugging?
View 1 Replies
View Related
Mar 9, 2014
For a few days now I have been trying to call variables (globes) from another CPP file so I can add/subtract data from them and use them in other places. I have my defines.h file working which contains all my constants but my defines.cpp (which is required to hold all the non constants) are not. Anyways I am getting the error :
Error1error LNK2001: unresolved external symbol "float MONEY" (?MONEY@@3MA)C:UsersJacksdocumentsvisual studio 2012ProjectsAssignmnet2Assignmnet2main.objAssignmnet2
My defines.cpp
//#include "Defines.h"
using namespace std;
//Game mechanic variables
extern float STOCK_LEMONS;
extern float STOCK_SUGAR;
extern float STOCK_ICE;
[Code] .....
If I were to un-comment the "float money = 50" it would work...
I also didn't include my defines.cpp into my defines.h as I got to many errors...
View 2 Replies
View Related
Jun 24, 2014
This is my first time working with C++ and I have put together this program and came up with two errors and I am unsure what it is wanting me to do. The errors I got are:
1>c:usersownerdocumentsvisual studio 2010projectsweek5week5passing_by_value.cpp(30): error C2064: term does not evaluate to a function taking 1 arguments
1>c:usersownerdocumentsvisual studio 2010projectsweek5week5passing_by_value.cpp(38): error C2064: term does not evaluate to a function taking 1 arguments
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
[Code].....
View 6 Replies
View Related
Sep 26, 2014
I don't have in depth code or anything. I tried this but can't seem to wrap my head around it.
Code: //header.h
namespace test {
int arr[5];
[Code] ....
Also tried putting int arr[5] in a Test class within test.h.
I have 2 structs in another file, the main, and want to make an instance of the arr variable, in a separate header, for each.
View 2 Replies
View Related
Aug 7, 2013
I have a structure
Code: struct time{
char hours;
char minutes;
char seconds;
char dummy;
};
I have kept dummy as the data to be aligned.I will update hours, minutes, and seconds , but will not use dummy in any case.
If I don't initialize 'dummy' does it make any errors ?
Do I need to initialize hours, minutes, seconds as well before I use the structure ?
If so is there any particular reason ?
View 6 Replies
View Related
Sep 26, 2014
I am working on a homework assignment and have most of the program working, but when I try to compile it keeps telling me to initialize the coin variables in each class. However, they are supposed to be added then removed so I don't want to set them back to zero.
Rewrite the Purse program given in Page 35 with functions to perform insert and remove operations. The function insert (int p, int n, int d, int q) will initialize pennies, nickels, dimes and quarters. The function dollars() will return the dollars. The function remove (int p, int n, int d, int q) will subtract pennies, nickels, dimes and quarters. The function display() returns a new String to print the content of the purse with remaining pennies, nickels, dimes and quarters.
Code:
usingnamespace std;
int insert_money (int *p, int *n, int *d, int *q);
int remove_money (int *p, int *n, int *d, int *q);
int dollars();
int main()
[Code] ....
View 2 Replies
View Related
Dec 14, 2013
The situation is the following :
Code:
vector<int>& function(int a , int b){
vector<int> s(3000000);
vector<int> xxx(4);
return xxx
}
Not to board people with details but if i am returning the the reference to a vector xxx what happens to vector s. is it destroyed ?? it should be, but i don't see it on my memory map (memory is not released) . can this be or should i go and search for error on some other place.....
View 2 Replies
View Related
Mar 4, 2014
What the code below is not doing is returning a value for item to my variables (item1, item2, etc..) I'm not sure how I can make a function prototype that will ask for input and basically recycle after going through the program to a new value for each item. I also need to input individual tax for each item. I will also post it in this message:
double tax, item,salesTax;
double cost(double);
double CalcSalesTax(double);
main(){
double total,item1, item2, item3, item4, item5, tax1, tax2, tax3,tax4,tax5;
[Code].....
View 13 Replies
View Related