So the question is to let the user put in two integers and put each integer in an array as separate numbers, and then sum these arrays together, so putting in the array is not so difficult, only problem i am having is first when the user have to input the first integer, he have to put space after each number, second then I am not sure how to sum them up, so if 45676 is first array and 56717 is second, we have to start summing them up from 6 and 7 (the last numbers). Here is what I did for now:
#include <iostream>
using namespace std;
int main () {
char Num1[5], Num2[5];
int i1; int i2;
cout << "input the first number" << endl;
for (i1=0; i1<5; i1++)
cin >> Num1[i1];
I am having a problem with my program to calculate the GPA of a student. The problem that I am having is that I am not able to get my Total Point Value to display the sum of the two arrays. The multiplication for the array is correct and will display correctly, but instead of putting the total into the accumulator it will display the totals in a column. I have tried moving the coding for the calculation out of the loop that converts the letter grade into a point value,and placing it in it's own loop, but I still get the same display output. Below is the code that I have so far. I still have a few elements to add to the code, but they will be easy once I get this display to work right.
#include <iostream> #include <iomanip> #include <fstream> using namespace std; // Global const // prototype int main () { // Varialbes, Arrays
I have been tasked with sorting a text file with some numbers in it. For example, there can be 5 numbers in it: 1,2,3, 4, and 5. However, they are out of order (3,2,4,1 and 5). I need the numbers in numerical order. How can you sort the numbers into a new file?
Bubblesorting? I can not use arrays in this program. I have already determined the minimum number in the file.
Add a program that declares two arrays of 5 integers each. Provide one function to load one array with random numbers from 1 to 25, another to fill the other array with user supplied values, and a third function to print an array. The main function should declare the arrays and use the functions to fill each array and print them both.
The code i have so far is #include <cstdlib> #include <iostream> using namespace std; void printaaray(int printarray1[], int printarray2);
Using PIONTER NOTATION ONLY, write a function that receives two arrays of integers like A and B above. The function should swap the values in A and B. You may NOT use array notation [ ]. Also, you have to use pointers to move among array cells. Note: Both arrays are of the same size, and size should be variable in the function.
I am having some problem with my quick sort problem. My program is supposed to create 5 arrays with 5,10,15,and 20 random integers, respectively. Then it should sort those arrays, where the numbers are bigger or smaller than the middle element in the original array! The program I wrote should do that but, its not! The program just keeps running infinitely!
#include <iostream> #include <cstdlib> using namespace std; void p(int k[],int left, int right) { int i = left, j = right;
I am working on a number of utility functions for two dimensional arrays of integers, or matrices. However I am having a problem with segmentation faults, most likely due to errors in using malloc in functions like copyMatrix.
Code: matrix_utils.h~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //This function checks if two matrices are equal int isEqual(int **A, int **B, int n);
//This function returns one row of a matrix int * getRow(int **A, int i, int n);
//This function returns one column of a matrix int * getCol(int **A, int j, int n);
In pseudocode and in C code, declare two 1-dimensional parallel arrays of Integers to store the age and weight of a group of people that will hold the information of up to 10 people. Use a For loop to iterate through the array and input the values. This is the code i have, but my array is showing up as 11 and not 10?
Basically, say i wanted to sum all the values enter for x. First, i ask the user how many x's there are, then create a "for" loop to ask for x1, x2, x3, .. xn. Then i want to know the cumulative total of x. How would i do this? This is the sample code i have made right now inside of my main function:
Code: int N; int I; int X; //This is where i ask for how many x's there are// }
I'm creating a program that is combining functions to show a menu to a user then the user picks numbered items which results in the totalling of a bill for them.
Where I'm stuck is after they're entered their selections, how to take them and sum them up. I've been trying with a switch statement, but I'm not sure if this is the right method. Is it even possible to sum separate cases of a switch statement together? Below is the code I've gotten so far:
I have to make a grid 40 X 40 with random numbers 0-9. I have already done this and it prints out great. My problem is I need to be able to choose a row number and output the sum of the number in that row. Here is what I have so far.
#include <iostream> using namespace std; int main(){ int Values[40][40]; int rows, cols;
Write a program that computes a running sum of inputs from the user, terminating when the user gives an input value of 0
Using a while loop - no problem. Its only when I try to code it with a for loop that the program doesn't terminate with a 0 input. It terminates with a -1 input!!
while loop
#include <iostream> using namespace std; int main() { float input=1; float sum = 0;
Write a program that reads characters from the keyboard using the getch() function. All lower case letters will be converted to upper case and printed out to the display using the putchar() function. All uppercase letters will be printed using putchar(). All individual digits will be accumulated and the sum will be printed at the end of the program using printf(). You will write a function to return the upper case of the letter and a second function which receives the current sum and the character digit.
The convert digit function will convert the character digit to a decimal value and accumulate the digit to the sum returning the new sum. Only the letters will be printed out nothing else. The program will continue until the return is received at which time the sum of the digits will be printed on the next line. What was entered: a9 wF23’;/4i What the line actually shows: aA9wWFiI The sum of the digits is: 18
I dont understand why it expects more () in the functions....
I'm a beginner at c++ and I need to write a program that reads a set of integers and then finds and prints the sum of the even and odd integers. The program cannot tell the user how many integers to enter. I need to have separate totals for the even and odd numbers. what would I need to use so that I can read whatever number of values the user inputs and get the sum of even and odd?
I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.
I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.
How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)
Code:
int _tmain(int argc, _TCHAR* argv[]) { int comm = 10; int targ = 5; int death; struct AI_WORDS
Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.
I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?
Code: #include<stdio.h> #include<stdlib.h> #include<math.h> int main () {
I'm trying to write a function that takes a 32bit address and a data to store at this address.
I'm wanting to take the 32 bit memory address eg 0x12345678 and split it into 4 x 2 bytes 12, 34, 56, 78
then each of the 4 entries is at most a 256 entry array.eg FF, FF, FF, FF
So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.
After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.
The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.
It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.
void cpu::store(unsigned int mem_add,unsigned int mem_val) { int first = (mem_address&4278190080)>>24; int second = (mem_address&16711680)>>16; int third = (mem_address&65280)>>8; int fourth= (mem_address&255);
Write a program, sumit.c, that reads an integer value n from the user and then sums the integers between 0 and n. Your program should be able to handle both positive and negative values of n and should write the sum to the output file sumitout.txt. Note that your sum should not actually include 0, since that doesn't affect the sum. Your program should open the file sumitout.txt for appending so that the file can record a series of runs.
For marking purposes run your program twice with values n = −10 and n = 5.
Here is a sample run:
Enter n: -4 The sum of integers from -1 to -4 is -1
#include<stdio.h> int main(void) { //declare your variables int n, i, term, total = 0; //promt user to enter and read a value of n printf("Enter n: "); scanf("%d", &n); //calculate the sum
i am relatively new to C programming so i run into problems on daily basis. But this time i have something i just cant figuer out and i was hoping you could point me towards the right track. I am trying to divide two integers.DevValue by KpTotal. for some reason my micro controller allways crashes.Y is a variable of a distance measuring sensor. i have a 4x4 keypad to enter a three digit number (e.i 123) so Kp1 = 1 Kp2 = 2 Kp3 =3.
Code:
int kp1, kp2, kp3, kpTotal = 0; char txt[6] = "" int keypadPort at PORTD; sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; }
[code]....
i think it has something to do with the format of the value. i read that the micro controller crash when dividing by zero.
How to write a simple function that will take 3 ints and find the sum of the higher 2? This is what i got so far:
int findsum(int a,int b,int c)// will find the highest int and return it to our main program { int max,max2;// this sets our local variable max // next we will find the larger of our first 2 variables if( a>=b) { max=a;
[Code] ....
How to get the second highest number and add it to max
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?