+ 1
Can you help me to edit code?
I try write program by using array of tow deminsions. but when I run code,it output is 10 this is code : #include<iostream> using namespace std; int main(){ int ar [4][5] ={10,20,30,40,50,-10,-20,-30,-40,-50,100,200,300,400,500,-100,-200,-300,-400,-500}; for (int i=0 ; i<4 ; i++) { for (int j=0 ; j<5 ; j++) { cout<<ar[i][j]<<"\t"; cout<<endl; return 0;} }} I want to output form as : 10 20 30 40 50 -10 -20 -30 -40 -50 100 200 300 400 500 -100 -200 -300 -400 -500 I am waiting to reply me
4 ответов
+ 2
the other issue is the addressing of the array. You need to address them as a list of rows.
int ar [4][5] ={{10,20,30,40,50}{-10,-20,-30,-40,-50}{100,200,300,400,500}{-100,-200,-300,-400,-500}}
0
return 0 should be after loops, other way you are breaking it
0
please help figure out whats wrong with this code
#include<iostream>
using namespace std;
int main()
{
int sum;
int diff;
int prod;
int div;
int x,y;
char opt;
char a,b,c,d;
cout <<"Please enter a number:" <<endl;
cin >>x;
cout <<"Enter another number:" <<endl;
cin >>y;
cout <<"Select if you want to add,subtract,multiply or divide the two numbers:" <<endl;
cout <<"a:addition" <<endl;
cout <<"b:subtract" <<endl;
cout <<"c:multiply" <<endl;
cout <<"d:divide" <<endl;
cin >> a;
cin >> b;
cin >> c;
cin >> d;
if (opt = a)
{
sum = x+y;
cout <<"The sum is:" <<sum <<endl;
}
else if (opt = b)
{
diff = x-y;
cout <<"The difference is:" <<diff <<endl;
}
else if (opt = c)
{
prod = x*y;
cout<<"The product is:" <<prod <<endl;
}
else if (opt = d)
{
div = x/y;
cout<<"The divisant is:" <<div <<endl;
}
else
{
cout<<"You did not select any of the above." << endl;
cout<<"Thank you try again." <<endl;
}
/* else
{
cout<<"wahh" <<endl;
}*/
return 0;
}
only the addition option works. this the only way I could get to you ......its basic but need the help thanks