| | |
Need help with some syntax errors
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2006
Posts: 4
Reputation:
Solved Threads: 0
Hi guys, I just found this site while doing a google search for "declaration syntax errors" and it looks like there are some great people here that are willing to take time to explain things which is what I need!
I'm in college taking c++ and my teacher doesn't tell us anything at all. Literally. He just gives us assignments and sets us free. This latest assignment is on Arrays, more specifically the program generates data for a sine waveform.
I feel like I have it almost complete (probably not the neatest code I know) but I can't get rid of errors enough to compile it.
He wants the program to input amplitude, frequency, duration and timestep (delta t) and generate a table with the time and the sine that looks something like this:
Time Sine
1 0
2 .5
3 1
4 .5
5 0
6 -.5
7 -1
8 -.5
9 0
ect...
So here is what I have so far:
I have gotten rid of most of my errors, syntax and logic, but I've run out of ideas and things to try.
The error I am currently getting is "Error E2141 lab8.cpp 25: Declaration syntax error"
What I don't get isline 25 is "int main()" I don't see what is an error about that.
Thank you in advance.
-Grant Bivens
I'm in college taking c++ and my teacher doesn't tell us anything at all. Literally. He just gives us assignments and sets us free. This latest assignment is on Arrays, more specifically the program generates data for a sine waveform.
I feel like I have it almost complete (probably not the neatest code I know) but I can't get rid of errors enough to compile it.
He wants the program to input amplitude, frequency, duration and timestep (delta t) and generate a table with the time and the sine that looks something like this:
Time Sine
1 0
2 .5
3 1
4 .5
5 0
6 -.5
7 -1
8 -.5
9 0
ect...
So here is what I have so far:
C++ Syntax (Toggle Plain Text)
//--------------------------- // lab8.cpp // Author: Grant Bivens // Class: EET 2303 C++ // Professor: Dr. Imad Abouzahr // Date: 4-4-06 // This program generates a table of values at specific times along a sine waveform. //--------------------------- #include <stdio.h> #include <stdlib.h> #include <cmath> // includes #include <iostream> #include <iomanip> using std::cout; using std::cin; // using standards. using std::endl; using std::setw; const float pi = 3.1415; //set pi as a constant so "pi" can be used instead of 3.141... // initalize function CalcWaveform void CalcWaveform ( double Waveform, int size, double frequency, double deltat, double amplitude ) int main() //begin main function { int wavesize; // initalize wavesize as integer double duration, deltat, amplitude, frequency; // initalized as double cout << "\nEnter duration"; // get duration cin >> duration; cout << "\nEnter Delta t"; // get delta t cin >> deltat; cout << "\nEnter wave amplitude"; // get amplitude cin >> amplitude; cout << "\nEnter wave frequency"; // get frequency cin >> frequency; wavesize = static_cast <int> ( duration / deltat ); //set size of wavesize double Waveform []; // initalize Waveform array for (int i = 0; i < wavesize; i++) //loop Waveform [ i ] = 0.0; // initalize array to 0 // call function CalcWaveform (Waveform , wavesize, frequency, deltat, amplitude); cout << "\nTime" << setw ( 13 ) << "Sine" << endl; // display header text // loop to fill waveform array for ( int h = 0; h < wavesize; h++ ) cout << setw ( 7 ) << h * deltat << setw ( 13 ) << Waveform [ h ] << endl; system ( "pause" ); return 0; } //start CalcWaveform function void CalcWaveform ( double Waveform, int size, double frequency, double deltat, double amplitude ) { int i; //initialize i for ( int i = 0; i < size; i++ ) // counter Waveform [ i ] = amplitude * sin ( 2 * pi * frequency * i * deltat ); // calculates cout << Waveform [ i ] << endl; // prints array results }
I have gotten rid of most of my errors, syntax and logic, but I've run out of ideas and things to try.
The error I am currently getting is "Error E2141 lab8.cpp 25: Declaration syntax error"
What I don't get isline 25 is "int main()" I don't see what is an error about that.
Thank you in advance.
-Grant Bivens
//---------------------------
// lab8.cpp
// Author: Grant Bivens
// Class: EET 2303 C++
// Professor: Dr. Imad Abouzahr
// Date: 4-4-06
// This program generates a table of values at specific times along a sine waveform.
//---------------------------
#include <stdio.h>
#include <stdlib.h>
#include <cmath> // includes
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin; // using standards.
using std::endl;
using std::setw;
const float pi = 3.1415; //set pi as a constant so "pi" can be used instead of 3.141...
// initalize function CalcWaveform
void CalcWaveform ( double Waveform, int size, double frequency, double deltat, double amplitude );
int main() //begin main function
{
int wavesize; // initalize wavesize as integer
double duration, deltat, amplitude, frequency; // initalized as double
cout << "\nEnter duration"; // get duration
cin >> duration;
cout << "\nEnter Delta t"; // get delta t
cin >> deltat;
cout << "\nEnter wave amplitude"; // get amplitude
cin >> amplitude;
cout << "\nEnter wave frequency"; // get frequency
cin >> frequency;
wavesize = static_cast <int> ( duration / deltat ); //set size of wavesize
double Waveform []; // initalize Waveform array
for (int i = 0; i < wavesize; i++) //loop
Waveform [ i ] = 0.0; // initalize array to 0
// call function
CalcWaveform (Waveform , wavesize, frequency, deltat, amplitude);
cout << "\nTime" << setw ( 13 ) << "Sine" << endl; // display header text
// loop to fill waveform array
for ( int h = 0; h < wavesize; h++ )
cout << setw ( 7 ) << h * deltat << setw ( 13 ) << Waveform [ h ] << endl;
system ( "pause" );
return 0;
}
//start CalcWaveform function
void CalcWaveform ( double Waveform, int size, double frequency, double deltat, double amplitude )
{
int i; //initialize i
for ( int i = 0; i < size; i++ ) // counter
Waveform [ i ] = amplitude * sin ( 2 * pi * frequency * i * deltat ); // calculates
cout << Waveform [ i ] << endl; // prints array results
}- in the error line
- right before the error line
- right after the error line.
In this case it was just before the error line 25. You missed a semicolon.
Oops. I forgot to tell you that we don't delete threads unless they are violating forum rules.
Edit.
I am closing this thread before it get's out of hand. But before that I should explain the reason for not deleting this or any other thread (incase other requests similar to this arise in the future). If you have any other questions, please contact me via PM.

Edit.
I am closing this thread before it get's out of hand. But before that I should explain the reason for not deleting this or any other thread (incase other requests similar to this arise in the future). If you have any other questions, please contact me via PM.
- The reason we offer free public help rather than private paid help is for newbies, like me and you, to learn from other people's mistakes and the solutions they came up with. If a thread gets deleted once it gets solved, that objective will not be achieved, and all the free, selfless, helpful effort put by the solution provider will be in vain. This is like open source. The more you share, the more you benefit in the whole.
- Deleting a thread deletes all the replies contained in it, along with the original posting. This discourages the helpful people from posting again, because they do not have a guarantee that their post will survive for others to learn.
- Daniweb holds a copyright for all the threads posted in this site. So after posting something, it is not your property but rather Daniweb's.
Last edited by WolfPack; Oct 22nd, 2006 at 3:20 am. Reason: Added further explaination.
バルサミコ酢やっぱいらへんで
![]() |
Similar Threads
- XML syntax error "){" (RSS, Web Services and SOAP)
- Invalid Syntax Error MS Explorer - Please help! (Web Browsers)
- syntax errors and the check module command? (Python)
- Understanding Syntax errors for C++ (C++)
- Simple Programming Errors (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: C++ Help....plez.
- Next Thread: How to compile C with Borland C++ V.6 Personal?
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





