473,382 Members | 1,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

perimeter of triangle

Hello,
Here is my code of a perimeter of a triangle such as:
2
1 7
3 6 8
4 2 5 3

#include <iostream>

using namespace std;

int perimeterSum (int[][]A, int Size);

int main()

}

int perimeterSum(int[][]A, int size){
int sum = 0;

// the left-hand side (the first column)

for (int i = 0; i < size; i++)
sum += A[i][0];

// the bottom row, except the first element

for (int i = 1; i < size; i++)
sum += A[A - 1][i];

// the diagonal except the first and last elements

for (int i = 1; i < size - 1; i++)
sum += A[i][i];

return sum;
}
}
i am only on chapter 3 so the code needs to be very basic using:
int perimeterSum (int[][] A, int Size) {
int sum = 0;
I tried this code but i got 4 errors in visual c++.

The errors are:
C:\Documents and Settings\perimeter.cpp(6) : error C2087: '<Unknown>' :
missing subscript

C:\Documents and Settings\perimeter.cpp(6) : error C2146: syntax error
: missing ')' before identifier 'A'

C:\Documents and Settings\perimeter.cpp(6) : error C2146: syntax error
: missing ';' before identifier 'A'

C:\Documents and Settings\perimeter.cpp(6) : fatal error C1004:
unexpected end of file found
Error executing cl.exe.

What am I doing wrong?

Nov 22 '05 #1
3 5684
You have to give at least one of the arrays a size in the formal parameter
in the signature of perimeterSum. And this size needs to be a constant.
Try to figure out which one it is and why.

On 19 Nov 2005 NJ*****@gmail.com wrote:
Hello,
Here is my code of a perimeter of a triangle such as:
2
1 7
3 6 8
4 2 5 3

#include <iostream>

using namespace std;

int perimeterSum (int[][]A, int Size);

int main()

}

int perimeterSum(int[][]A, int size){
int sum = 0;

// the left-hand side (the first column)

for (int i = 0; i < size; i++)
sum += A[i][0];

// the bottom row, except the first element

for (int i = 1; i < size; i++)
sum += A[A - 1][i];

// the diagonal except the first and last elements

for (int i = 1; i < size - 1; i++)
sum += A[i][i];

return sum;
}
}
i am only on chapter 3 so the code needs to be very basic using:
int perimeterSum (int[][] A, int Size) {
int sum = 0;
I tried this code but i got 4 errors in visual c++.

The errors are:
C:\Documents and Settings\perimeter.cpp(6) : error C2087: '<Unknown>' :
missing subscript

C:\Documents and Settings\perimeter.cpp(6) : error C2146: syntax error
: missing ')' before identifier 'A'

C:\Documents and Settings\perimeter.cpp(6) : error C2146: syntax error
: missing ';' before identifier 'A'

C:\Documents and Settings\perimeter.cpp(6) : fatal error C1004:
unexpected end of file found
Error executing cl.exe.

What am I doing wrong?


Nov 22 '05 #2

<NJ*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hello,
Here is my code of a perimeter of a triangle such as:
2
1 7
3 6 8
4 2 5 3

#include <iostream>

using namespace std;

int perimeterSum (int[][]A, int Size);

int main()

}

int perimeterSum(int[][]A, int size){


Problem here. int[][]A says it's a 2 dimentional array, but C++ has no idea
what size it is because you didn't tell it. So how is it suppose to figure
out which memory address [2][2] is supposed to point to? It knows normally
by: row*TotalColumns + Column. So obvoiusly you have to let C know what teh
total columns is at least.

Is this a 4x4 array? then let it know.
Nov 22 '05 #3

<NJ*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hello,
Here is my code of a perimeter of a triangle such as:
2
1 7
3 6 8
4 2 5 3

#include <iostream>

using namespace std;

int perimeterSum (int[][]A, int Size);

You can't leave both dimensions unspecified. You have to specify at least
the first dimension (or use pointers).
int main()

}
Is this really your code? You open a function with the _left_ curly
bracket: {, not }.

Is this function _inside_ your main function? Why? It should be declared
either before or after your main function. (After is ok, because you gave
it a prototype above.)
int perimeterSum(int[][]A, int size){
int sum = 0;

// the left-hand side (the first column)

for (int i = 0; i < size; i++)
sum += A[i][0];

// the bottom row, except the first element

for (int i = 1; i < size; i++)
sum += A[A - 1][i];

// the diagonal except the first and last elements

for (int i = 1; i < size - 1; i++)
sum += A[i][i];

return sum;
}
}
i am only on chapter 3 so the code needs to be very basic using:
int perimeterSum (int[][] A, int Size) {
int sum = 0;
I tried this code but i got 4 errors in visual c++.

The errors are:
C:\Documents and Settings\perimeter.cpp(6) : error C2087: '<Unknown>' :
missing subscript

C:\Documents and Settings\perimeter.cpp(6) : error C2146: syntax error
: missing ')' before identifier 'A'

C:\Documents and Settings\perimeter.cpp(6) : error C2146: syntax error
: missing ';' before identifier 'A'

C:\Documents and Settings\perimeter.cpp(6) : fatal error C1004:
unexpected end of file found
Error executing cl.exe.

What am I doing wrong?


It would also help if you let us know exactly what line 6 is, by commenting
it in the code you post.

-Howard

Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: coinjo | last post by:
I need to write a program, which takes two inputs: •a value n that represents the number of elementsin the longest row of a triangle. •a character c to be printed in place of each...
16
by: VISHNU VARDHAN REDDY UNDYALA | last post by:
Hi, Could anyone over here, write a program in C using only for loop to print the following output * *** ***** ******* ********* ***********
2
by: javadkhan | last post by:
Hi All, I am trying to supress the small black triangle that shows up in the menus meaning the menuitem is parent. The reason for that is I drew my own 3D looking triangle in DrawItem using...
0
by: NJpixie | last post by:
Hello, Here is my code of a perimeter of a triangle such as: 2 1 7 3 6 8 4 2 5 3
1
by: NJpixie | last post by:
Hello, Here is my code of a perimeter of a triangle such as: 2 1 7 3 6 8 4 2 5 3
5
by: singhm | last post by:
Hi guys so I have a trianlge program having hard time finishing this though, I have to develop a program which is the following: Write a program that will allow the user to enter the 3 lengths...
0
geo039
by: geo039 | last post by:
I have a program that takes user input from a textbox. Based on those 3 numbers it will tell them whether it is a right triangle, equilateral triangle or not a triangle. I've written 3 constructors...
19
by: lost1 | last post by:
Can someone point me in the right direction on how to get the triangle type to display. Below is a triangle class that is tested by another completely separate class. The main method of the test...
6
by: jackj | last post by:
Hi, I am first time C++ student and doing the usual tasks. This one is to create a triangle based on user input of how large (how many rows) and what symbol to use. I have managed to create a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.