0
Someone please help me with my school assignment
QUESTION: Write a program that accepts data in one dimensional arrays Addition, multiplication, division and subtraction. Any two arrays that you have created. -Array should be minimum of 3. **in C++
53 Respuestas
+ 3
You should be able to figure out some of it. Do so and post it to get suggestions on finishing it.
+ 3
You should do your homework yourself and not ask people to do it for you. If you have trouble doing it, then post your code and then we will help you. 😉
+ 2
First, before declaring values, you should read first_number and second_number. You're array currently has garage in it because they haven't been read as yet.
Second, you are meant to have two arrays based on your initial question so you need to do it twice.
Third, you need to use loops to do each operation on the two arrays either storing into a third array to be printed later or directly print it as you go.
+ 2
+ 2
Oh thanks i see where i went wrong i have to input my numbers first before put them in the array memory
+ 1
Ok this is what I've been able to do , the only problem is ,I don't want it display each calculation if i could be able to call the specific calculation for example if i wanted to perform addition then the program would show the result of addition only and not the rest😀thank you
#include <iostream>
using namespace std;
int main() {
int first_number;
int second_number;
int values[]={first_number,second_number};
cin>>first_number;
cin>>second_number;
int sum;
sum = first_number+second_number;
cout<<sum<<endl;
int subtraction;
subtraction=first_number-second_number;
cout<<subtraction<<endl;
int multiply;
multiply=first_number*second_number;
cout<<multiply<<endl;
int division;
division=first_number/second_number;
cout<<division<<endl;
return 0;
}
+ 1
Start out like
int first_number;
int second_number;
char op;
cin>>first_number;
cin>>second_number;
int values1[]={first_number,second_number};
cin>>first_number;
cin>>second_number;
int values2[]={first_number,second_number};
int values3[2];
cin>>op;
switch (op){
case '+':
+ 1
I know the question requires a second array but I don't know what to do with them once i read them? What will be the use of values2 and values3?
Heres the modified code
https://code.sololearn.com/cLCoCjtE5U9F/?ref=app
+ 1
You need to add like:
values3[i]=values1[i]+values2[i]; for i = 0 and 1.
+ 1
values1[] = {3, 5}; values2[] = {4, 6}; values3[] = {3+4, 5+6} = {7, 11}
+ 1
https://code.sololearn.com/cy2yEKZwmM2d/?ref=app
Here is what I have to add to this discussion. I only did the addition.
0
Please take your code and link it here. I am willing to walk you through the coding process, but we both need access to the same code.
0
Thank you,,how do i link the code here?
0
I'm using the app
0
Under the line you type in, there is a plus sign and insert. Tap that. Select code. Select my Codes. Tap on your program and a web link will be added to your post.
0
Thats it
0
What do you mean when you say my array has a garage in it?
0
You didn't put anything in your numbers as yet so you might get zero or whatever value was in that memory location left behind by something else. That's garbage as it is some random value. That is one of the worst bugs to find in a program because it causes random behavior.
0
The program needs to accept numbers as you run it and execute them,,so I'm not really getting what you're saying