C++ :: Generates Random Addition For Subtraction Depending On User Choice

Feb 17, 2012

Below is a program that generates random Addition for Subtraction problems depending on the user's choice. The user is prompted to input an answer and then it keeps your score. If you want to quit you just press zero.

Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
#include <string>
using namespace std;
int menu();
bool addition(int &reward); // function to return truth values

[Code] ....

View 14 Replies


ADVERTISEMENT

C/C++ :: Matrix Class - Addition / Subtraction

Jul 7, 2014

I'm working on a matrix class and I've hit a few snags. Here's what I've got so far:

Matrix.h

#include <iostream>
#include <conio.h>
using namespace std;
class Matrix {
private:
int matrix[50][50];

[Code] ....

Where I have questions is in implementing the addition and subtraction bits into the class itself. I understand that I'm going to have to do a copy operation (this from reading in C++ Primer Plus 5th Edition). Right now I'm just after adding/subtracting as the rest will be variations on the same theme.

So, here it goes:

As I understand the problem, I need to pass my two matrices as arguments to an addition function. This is going to involve having to copy the values of the two existing matrices into temporary matrices within the addition function, then I'll add them, and store them in a new matrix which will be my return value. So...something like this:

int Matrix::matrixAdd(int R, int C, const Matrix & matrix1, const Matrix & matrix2) {
int sum;
Matrix matrix;
for (int i = 0; i < R; i++)

[Code] ....

I do end up with errors there...C2240, and C2662. Again, I'm new to working through this, but that's what I've got. My idea is that I'm passing the maximum size of the array as defined by the user, in this case a 2x2 array, it'll cycle through and add up to that imposed limit...I went 2x2 because it's small enough that testing doesn't drive me up a wall.

View 14 Replies View Related

C :: Addition And Subtraction Calculator That Takes Input?

Feb 23, 2013

I'm writing an addition and subtraction calculator that takes input as: 5+6-3+2. You should be able to add or sub as many numbers as you want. I want the while loop to stop when the user hits enter. I put the getchar() function to catch the and break the loop but it is also swallowing the '-' sign, which I want to use to subtract and is instead adding the numbers with "sum+=number". How can I get around that?

Code:

#include <stdio.h>
int main(int argc, char *argv[]){
int number, sum = 0;

[Code]....

View 3 Replies View Related

C# :: Regex For Addition Of Integers And Subtraction Of Complex Numbers

Jan 12, 2015

1.What would regex pattern look like for addition of integers?

2.What would regex pattern look like for subtraction of complex numbers?

View 1 Replies View Related

C++ :: Random Generator Generates Same Numbers Each Time?

Apr 24, 2014

The user thinks of a number from 0 to 100 and the program tries to guess it. The problem is, I'm new to random numbers and use a function to generate them that isn't my own. It generates the same numbers each time the program runs, here are screen shots:

Run 1: [URL] .....

Run 2: [URL] .....

I read something about seeding or something, if I need it, must don't give me the answer. If you have the liberty of time explain more to me about the random business.

Here is my code:

#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <unistd.h>
#include <string>
#include <ctime>
using namespace std;
int rand_lim(int limit) {

[Code] ....

View 4 Replies View Related

C/C++ :: Function That Generates A Random String Of Uppercase Letters

Apr 19, 2014

I need to write a C function that generates a random character array (i.e. string) of uppercase letters - getchar and putchar are the only IO functions that I can use. Below is what I have already - I am iterating for as many times as I am required to, and am modulating rand() by 25, (total letters in the alphabet). I'm trying to see how to get the random letter from the % 25, and also how to do this without toupper() [not sure if I can use that function].

void getRandomStr()){
char str[40];
for (int i = 0; i < 40; i++){
char c = rand() % 25);
str[i] = toupper(c);
}}

View 5 Replies View Related

C++ :: Loop Depending On User Input

Jul 31, 2013

I'm trying to get this program to loop the number of times I get it to input. The program compiles alright, and it does loop when I tell it too, but how do I output the grades of the multiple students?

#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
int weighted1 = 0;
int weighted2 = 0;

[Code] .....

View 12 Replies View Related

C/C++ :: 5x5 Multiplication Table Starting With The Number Of User Choice?

Feb 23, 2014

#include <stdio.h>
#include <stdlib.h>
int n;
int m;
char input[20];
int num;
int main() {
int num0;

[code]....

I'm supposed to write C program that will generate a 5 X 5 multiplication table starting with the number of the users choice. The program is supposed to operate within a loop and run until the user indicates that they no longer wish to enter any more numbers. I can get the program to run but am wondering what I need to do to get the program to ask for another number and how to make the program stop when the user no longer wants to play. Should I start with "Do you want to enter a number" if yes, run back through loop if no, goodbye?

View 8 Replies View Related

C# :: Using Different Instance Of Class Depending On User Input?

Jan 13, 2015

Here's the problem I want to intialise different classes based on user input. I've tried using an IF statement but the scope of an if statement would mean the rest main program wouldn't be able to see it.

View 12 Replies View Related

C++ :: Calculate GPA - Divide Depending On How Many Times User Inputs A Value

Feb 27, 2014

For example, to calculate GPA, we add all the grade point of a course and divide by the number of courses we are taking. How do I create a program in such a way that when the user enters grade point for two courses, it will add the grade points for the two course and divide by 2. And if another user enters grade points for six courses, it adds the grade points and divides by 6.

View 2 Replies View Related

C++ :: User Input Data About Percentages To Calculate Final Grade - Addition Error?

Sep 15, 2014

I am trying to code a program that takes in user inputted data about percentages and using it to later on calculate a final grade. 4 percents are inputted, for Assignments, Midterm1, Midterm2, and Finals. If the percents dont add up to 1 (i tell the user to enter the decimal value) I set up and if statement to catch it and end the program. Except that if i type in

Assignments = .3
Midterm1 = .3
Midterm2 = .3
Finals = .1

the program doesn't recognize that they add up to 1. Heres the relevant portion of my code [URL] ....

Here's some examples of how it works [URL] ....

And heres what i dont understand [URL] ....

Why is it saying .3 + .3 + .3 + .1 != 1 when .1 + .3 + .3 + .3 == 1?

View 1 Replies View Related

C++ :: Infinite Loop When Program Generates New Bracket

Feb 14, 2014

I am getting an infinite loop when my program generates a new bracket

#include <iostream>
#include <string>
#include <stdlib.h>
#include <numeric>
#include <fstream>
#include <vector>
using namespace std;
const int MAXTEAMS = 20;
const char* c;

[Code] ....

View 2 Replies View Related

C++ :: Program That Takes Sum Of Products And Generates Sum Of Minterms

Nov 28, 2013

Write a C/C++ program that reads a boolean expression in sum-of-products form and generates the sum-of-minterms form (canonical form). Use single letter to represent variables. The following symbols will be used to represent operators: NOT: ~, AND: *, OR: +. Other operators won't be used.

Examples of execution:
number of variables: 2
SOP expression: ~A+B
output: ~A*~B + ~A*B + A*B

number of variables: 3
SOP expression: x*y*z + ~x*~y + y*~z
output: x*y*z + ~x*~y*z + ~x*~y*~z + x*y*~z + ~x*y*~z

View 3 Replies View Related

C++ :: Program That Generates 5 Non Duplicate Numbers Between 1 And 20 By Using Arrays

Nov 4, 2014

program that generates 5 non duplicate numbers that is between 1 and 20 by using arrays. Here is my code and i cant compile it.

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
using namespace std;
int main() {
srand(time(NULL));

[Code]...

View 3 Replies View Related

C++ :: Partly Recompilation Generates Invalid Address Fault?

Jun 1, 2013

I'm making an x86 emulator with C++ (currently 8086/80186 with some little unfound errors). When I'm compiling all the files (deleting all *.o files and running make), the emulator runs fine (still some errors, but it runs). When I run make, just having one file adjusted, the emulator (JPCSP, a PSP emulator) gives me an invalid opcode/address fault. The emulator does use some pointers at different places though (mostly dynamic memory and optimization), can this be the cause? Causing addressing errors with partial recompilation using make?

View 1 Replies View Related

C++ :: Random Number Generator - How To Get User Inputs

Sep 10, 2013

I want to program a program that produces a random number between 1-10, then if the number is correct, says like HEY GOOD JOB and if its not says try AGAIN! also, at any point the user can quit by typing in X.

I know that I can use stuff like cout << "Hey put in a guess now" to prompt the user but I dont know how to accept inputs.

For example, how do I use scanf to do this?

I know that if I use scanf, it takes in a value, but where the heck does it store it?

eg. scanf(%s,guess);

Is that valid? I get an invalid expression error when trying to use that in C++.

View 3 Replies View Related

C++ :: Subtraction Of Two Integers?

Apr 18, 2014

I am working on an assignment where I have to subtract two very large integers. How can I write it's code provided that I have both numbers in a character array with each index holding a fraction of the original number. Like if I have a number 123456789 in an array then

arr[0]='1';
arr[1]='2';
arr[2]='3';
arr[3]='4';
and so on. n

nNw if i have to subtract this number from an other number, how can I do that?

View 4 Replies View Related

C++ :: Generate Random Number Between Two Numbers (User Input)

Jul 26, 2014

I am trying to generate a random number between two numbers that the user gives me.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void rand_int(const int &min, const int &max, int &val);

[Code] .....

View 3 Replies View Related

C/C++ :: Subtraction - Two Time Intervals

Mar 12, 2014

I am looking for simple code that subtract two time interval. I have time t1=5hour 30 minute and other time in 24 hour format. This code i written but it not working as expected

main() {
intTime1;
intTime2;
int hour=10;
int minute=5;
int second=13;
int h;int m;

[Code] ....

Is there any easy way of doing above code. Above two code section not working....

View 8 Replies View Related

C++ :: Variable Length Integer Subtraction

Aug 24, 2013

On a controlled buffer of unsigned char it is possible to do subtraction faster than if you followed standard mathematical rules, here is an example:

typedef unsigned char uchr;
uchr num1 = 5; //00000101
uchr num2 = 3; //00000011
num2 = ~num2; // 11111100
++num2; // 11111101
uchr num3 = num1 + num2; // 00000010(2) - computer truncates result to fit char

Since you will be working with a buffer you don't even need to worry about truncating the final bit because the add function will not be able to reach it - unless it is given the ability to grow the buffer in which case you just set the bit to 0 yourself

View 8 Replies View Related

C++ :: Sorting User Defined Amount Of Random Numbers In Ascending Order

Jan 30, 2013

I want to implement a function into the code below that sorts the user defined amount of random numbers and then sorts them in ascending order.

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <string>

using namespace std;
class IntegerArray {

[Code] ....

View 5 Replies View Related

C++ :: Search User Input Number In Array Filled With Random Numbers

Nov 6, 2014

I need to create A program That makes a 12x10 Array Grid Filled With Random Numbers From 0-99.

Then I need To Allow The User To Input A Number Between 0-99 And Then The program will then search through the array and count how many of the users number there is inside the array.

Code:

#include <iostream>
using namespace std;
int main() {
int input;
int number;
int row=0;
int col=0;
int Array [12][10];

[Code] ....

View 1 Replies View Related

C++ :: Perform Subtraction Between Two Objects And Put Result In Third Object

Sep 19, 2013

trying to understand operator overloading, and i wrote some code just to define a "-" operator to do a simple subtraction. SO, i wrote a program that can perform a subtraction between two objects and put the result in the third object. now I Just cant show the result on the console. And also can anyone define the meaning of [b1.x], like I want to know am I assigning the value to the "b1"object or the x variable? This is a very concept that I need to understand.

#include<iostream>
using namespace std;
struct Ok
{
int x;
int y;
};

Ok operator-(const Ok& a , const Ok& b)

{
Ok result;
result = (a - b);
return result;
}
int main()

[Code]...

View 2 Replies View Related

C++ :: Creating Binary Calculator - Output Operation Of Subtraction

Feb 10, 2014

I need to create a binary calculator that outputs the operation of subtraction whenever you input 2 4 bit binary numbers. For example:

If I enter

1000
- 0111

View 1 Replies View Related

C++ :: Randomized Multiple Choice

Feb 20, 2012

I have gotten my code sorted out, and now it works. But to be adaptable to 3pi robots, which I will be loading it into eventually, the user has to be given three letter (a, b, c) multiple choices for answer input to the math questions. The three choices have to be randomized everytime the program loops too. Currently it just runs on number input.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int menu();
void addition(int *Preward); // function to return truth values
void subtraction(int *Preward);

[Code] ....

View 4 Replies View Related

C++ :: Specific Iterator Type - Find Distance By Simple Subtraction

Sep 24, 2014

I have a templated container that defines a forward iterator.

Calling std::distance on these iterators will generate code that will count the number of iterations it takes to get from the first parameter to the second, by repetitively incrementing.

Internally, the iterators can easily find the distance by a simple subtraction.

What I want to do is overload std::distance for these iterators so that it will take advantage of the simple calculation rather than repetitive increments.

The simple solution of course would be to make the iterators random access, but this would require that they support functionality that is not 'logical' for the container. Access to the container only makes logical sense when iterating one item at a time in the forward direction.

Code:
#include <iterator>
template <typename T>
class Container {
public:
class iterator : public std::iterator<std::forward_iterator_tag, T> {

[Code] .....

View 2 Replies View Related







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