How can I change a value in an array?

Need help in inputing numbers into an array and adding them together?

  • My professors wants us to do the following: If you need to work with very large integers (for example, data encryption program), you may not be able to use type int. An array can be used to store large integers one digit at a time. For example, the integer 1234 could be stored in an int array a by setting a[0] to 1, a[1] to 2, a[2] to 3, and a[3] to 4. However, for this project you might find it easier to store the digits backward, so place 4 in a[0], 3 in a[1], 2 in a[2], and 1 in a[3]. Write a program to perform simple basic arithmetic operations with large integers. Your program shall read a positive integer that is 20 or fewer digits in length, an operator (+ or -), and another positive integer that is 20 or fewer digits in length. It then outputs the sum or difference of the two numbers. For subtraction, you can assume that the first operand is larger than or equal to the second operand. It is easiest to input each operand as a string (c-string or C++ string), but you can also read each digit as value of type char so that the number 1234 is read as the four characters '1', '2', '3', and '4'. Do not attempt to read a number as type int because it can be larger than an int can hold. After they are read into the program, the characters should be changed to values of type int and should be stored in reverse order in an int array. Your program will perform the calculation by implementing the usual paper-and-pencil addition or subtraction algorithm. The result is stored in an int array and it is then written to the screen. Your program must allow the user to continue until the expression 0 % 0 is entered. The following is a sample run of the program and you must follow its user-interface. [Some information about your program] Enter an expression --> 1234 + 72<Enter> 1234 + 72 = 1306 Enter an expression --> 10000000000 - 1<Enter> 10000000000 - 1 = 9999999999 Enter an expression --> 123456789012345678901 - 5<Enter> Integer overflow. Enter an expression --> 0 % 0<Enter> Good bye! Your program shall also reject an invalid operator or an operand that has a length longer than maximum allowed digits. If the result is an integer with more than the maximum number of digits (i.e., more than 20 digits), then your program shall issue a message saying it has encountered "integer overflow." You should be able to change the maximum length of the integers by changing only one globally defined constant. It is probably easier to check out your program with shorter-length integers. Make sure to properly utilize functions in your program or points will be deducted How should I start. How would I setup the array so it accepts inputs like that. Any help would be appreciated how do I go about inputting numbers into an array and add them to get a total and display that total

  • Answer:

    At this point, if you can't figure out something this simple on your own AND don't even feel compelled to write any code yourself, there is no point helping you. Drop the class and change majors. You don't have what it takes to program anything.

Wertle Woo at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

At this point, if you can't figure out something this simple on your own AND don't even feel compelled to write any code yourself, there is no point helping you. Drop the class and change majors. You don't have what it takes to program anything.

Wertle Woo

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.