Need help with some syntax errors

Please support our C++ advertiser: Intel Parallel Studio Home
Closed Thread

Join Date: Apr 2006
Posts: 4
Reputation: rgbivens is an unknown quantity at this point 
Solved Threads: 0
rgbivens rgbivens is offline Offline
Unverified User

Need help with some syntax errors

 
0
  #1
Apr 7th, 2006
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:

  1. //---------------------------
  2. // lab8.cpp
  3. // Author: Grant Bivens
  4. // Class: EET 2303 C++
  5. // Professor: Dr. Imad Abouzahr
  6. // Date: 4-4-06
  7. // This program generates a table of values at specific times along a sine waveform.
  8. //---------------------------
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <cmath> // includes
  13. #include <iostream>
  14. #include <iomanip>
  15. using std::cout;
  16. using std::cin; // using standards.
  17. using std::endl;
  18. using std::setw;
  19.  
  20. const float pi = 3.1415; //set pi as a constant so "pi" can be used instead of 3.141...
  21.  
  22. // initalize function CalcWaveform
  23. void CalcWaveform ( double Waveform, int size, double frequency, double deltat, double amplitude )
  24.  
  25. int main() //begin main function
  26. {
  27. int wavesize; // initalize wavesize as integer
  28. double duration, deltat, amplitude, frequency; // initalized as double
  29.  
  30. cout << "\nEnter duration"; // get duration
  31. cin >> duration;
  32.  
  33. cout << "\nEnter Delta t"; // get delta t
  34. cin >> deltat;
  35.  
  36. cout << "\nEnter wave amplitude"; // get amplitude
  37. cin >> amplitude;
  38.  
  39. cout << "\nEnter wave frequency"; // get frequency
  40. cin >> frequency;
  41.  
  42. wavesize = static_cast <int> ( duration / deltat ); //set size of wavesize
  43. double Waveform []; // initalize Waveform array
  44. for (int i = 0; i < wavesize; i++) //loop
  45. Waveform [ i ] = 0.0; // initalize array to 0
  46.  
  47. // call function
  48. CalcWaveform (Waveform , wavesize, frequency, deltat, amplitude);
  49. cout << "\nTime" << setw ( 13 ) << "Sine" << endl; // display header text
  50.  
  51. // loop to fill waveform array
  52. for ( int h = 0; h < wavesize; h++ )
  53. cout << setw ( 7 ) << h * deltat << setw ( 13 ) << Waveform [ h ] << endl;
  54. system ( "pause" );
  55. return 0;
  56. }
  57.  
  58. //start CalcWaveform function
  59. void CalcWaveform ( double Waveform, int size, double frequency, double deltat, double amplitude )
  60. {
  61. int i; //initialize i
  62.  
  63. for ( int i = 0; i < size; i++ ) // counter
  64.  
  65. Waveform [ i ] = amplitude * sin ( 2 * pi * frequency * i * deltat ); // calculates
  66. cout << Waveform [ i ] << endl; // prints array results
  67. }

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
Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Need help with some syntax errors

 
0
  #2
Apr 7th, 2006
//---------------------------
// 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
}
Usually you should look
  • 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.
Quick reply to this message  
Join Date: Apr 2006
Posts: 4
Reputation: rgbivens is an unknown quantity at this point 
Solved Threads: 0
rgbivens rgbivens is offline Offline
Unverified User

Re: Need help with some syntax errors

 
0
  #3
Oct 20th, 2006
MOD - Please remove this thread. It is indexed on google and do not wish for it to be viewable any longer.

Thank you,
-Grant
Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Need help with some syntax errors

 
0
  #4
Oct 20th, 2006
Originally Posted by rgbivens View Post
MOD - Please remove this thread. It is indexed on google and do not wish for it to be viewable any longer.
Why?
バルサミコ酢やっぱいらへんで
Quick reply to this message  
Join Date: Oct 2006
Posts: 2,819
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Roasting Maven

Re: Need help with some syntax errors

 
0
  #5
Oct 20th, 2006
It probably was his homework assignment and he's affraid his teacher going to find out
Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Need help with some syntax errors

 
0
  #6
Oct 20th, 2006
Na.. he is afraid that his friends might stumble across this same snippet while reasearhcing and submit the same as assignment.
I don't accept change; I don't deserve to live.
Quick reply to this message  
Join Date: Apr 2006
Posts: 4
Reputation: rgbivens is an unknown quantity at this point 
Solved Threads: 0
rgbivens rgbivens is offline Offline
Unverified User

Re: Need help with some syntax errors

 
0
  #7
Oct 21st, 2006
Yes, it was one of my homework assignments from last semester. No, I do not care if my professor stumbles across it. I already have my grade for the class.

I am trying to get rid of the amount of stuff that comes up when people google me.
Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Need help with some syntax errors

 
0
  #8
Oct 21st, 2006
why would people want to google for you?
バルサミコ酢やっぱいらへんで
Quick reply to this message  
Join Date: Apr 2006
Posts: 4
Reputation: rgbivens is an unknown quantity at this point 
Solved Threads: 0
rgbivens rgbivens is offline Offline
Unverified User

Re: Need help with some syntax errors

 
0
  #9
Oct 22nd, 2006
Holy cow, this isn't rocket science...

I have asked nicely for this thread to be removed.

Does it matter why people would google me? No, that has absolutly NOTHING to do with you removing this thread.

Now I ask again PLEASE remove this thread.

Thank you,
-Grant
Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Need help with some syntax errors

 
0
  #10
Oct 22nd, 2006
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.
  1. 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.
  2. 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.
  3. 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.
There are a lot more reasons that I can think of, but the above three should be the most important.
Last edited by WolfPack; Oct 22nd, 2006 at 3:20 am. Reason: Added further explaination.
バルサミコ酢やっぱいらへんで
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC