Help!!!!!!!! What Am I Doing Wrong????

This is a discussion on Help!!!!!!!! What Am I Doing Wrong???? within the C++ Programming forums, part of the General Programming Boards category; I been working on these two projects forever and I have to turn them in tomorrow. I keep receiving errors ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    5

    Angry Help!!!!!!!! What Am I Doing Wrong????

    I been working on these two projects forever and I have to turn them in tomorrow. I keep receiving errors and now I'm out of answers. One project I received help from someone, but my teacher said the coding was wrong. Please help!

    Project 1: You are writing a code to find the greatest common divisior (gcd) Write a recursion function to find the gcd, returns integer with two integer arugmentss n amd m. Use gcd(m,n%m) format. if one of the two integerss is 0, the gcd will be the 2nd integer. tell the user to enter -1 for exiting.

    Ok, here are the errors I'm receiving for this code:

    error C2146: syntax error : missing ';' before identifier 'cout'
    error C2065: 'end1' : undeclared identifier
    error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'int (__cdecl *)(int,int)' (or there is no acceptable conversion)
    error C2065: 'm' : undeclared identifier
    error C2065: 'n' : undeclared identifier
    error C2143: syntax error : missing ';' before '}'
    error C2143: syntax error : missing ';' before '<<'
    error C2501: 'cout' : missing storage-class or type specifiers
    error C2371: 'cout' : redefinition; different basic types (same error for 'cin')
    error C2447: missing function header (old-style formal list?)
    fatal error C1004: unexpected end of file found

    Code:
    #include<iostream.h>
    
    
    int gcd (int n, int m)
    
    {
    	if (m==0)
    		return n;
    
    	else
    		return gcd (m,n%m);
    
    
    }
    
    void main ()
    
    {
    
    	int gcd (int n, int m)
    
    	cout<<"Enter n,m ?"<<end1;
    	cout<<"The greatest common divisor gcd"<<end1;
    	cin>>gcd;
    	
    	while (m>n)
    
    }
    
    
      cout<<"Have a Nice Day"<<end1;
      cin>>gcd;
    
      {
    project 2: Calcukate the average of a series if test scores where the series is dropped. GetValues should ask for five test scores and store them in variables. findlowest should determine which of the five scores if the lowest, return value. CalcAverage should calculate and display the average of the four highest scores.

    Code:
    #include <iostream.h>
    
    void main ()
    {
    	void Getvalues(); // prototype of function
    	double Getvalues (double x[]);
    	int scores, x;
    	cout<<"Please enter values";
    	for(x = 0; x <=5; ++x){
    		cin>>scores [x];
    	}
    
    	void findlowest ()
    	double findlowest [5];
    	int lowest = scores[0];
    	for (x =0; x<= 5; ++x)
    		if (x<lowest)
    			scores = x;
    		else
    			return scores;
    
    	}
    	void calcaverage ()
    	double calcaverage [4];
    	int highest= scores [0];
    	for (int x = 0; x<=100; ++x);
            if (scores < highest)
    			highest=scores ;
    	}
    		cout<<"The average is"<<calcaverage<<end1;
    
    		cout<<"Have a nice day"<<calcaverage<<end1;
    	
    	}
    Last edited by Cnote; 05-19-2002 at 09:33 PM.

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    I know this probably isn't much help to you, but if you want help you're far more likely to get it, if you tell people what the problem is you're having... what compiler, and what the error messages are.

    Or if it compiles, what the program is doing wrong, a lot of people that could help aren't going to go to the trouble of compiling your code to help you debug it.

    You seem to have a braces issue in program 2, is that all of the code?

    void main(), umm no....
    int main (void), and return 0 at the successful completion of program.

    You have helped your cause with code tags though, well done.

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Yes, major issues with the braces there.
    You also missed a bunch of semicolons, as well as put some semicolons after your for-loops.

    As a rule of thumb, I always use braces, even if theres only one statement after a loop or if statement... this prevents you from making errors like those in your code.

    I revised your code the best I could

    Code:
    #include <iostream.h>
    
    int main ()
    {
    	void Getvalues(); // prototype of function
    	double Getvalues (double x[]);
    	int scores, x;
    	cout<<"Please enter values";
    
    	for(x = 0; x <=5; ++x)
    	{
    		cin>>scores [x];
    	}
    
    	void findlowest ();
    	double findlowest [5];
    	int lowest = scores[0];
    
    	for (x = 0; x <= 5; ++x)
    	{
    		if (x<lowest)
    		{
    			scores = x;
    		} else {
    			return scores;
    		}
    	}
    	void calcaverage();
    	double calcaverage[4];
    	int highest = scores [0];
    
    	// for (int x = 0; x<=100; ++x); I can't figure out why that is stuck in there;
            if (scores < highest)
    	{
    			highest = scores;
    	}
    	cout<<"The average is"<<calcaverage<<end1;
    	cout<<"Have a nice day"<<calcaverage<<end1;
    
    	return 0;
    	
    }

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    5
    Project 2 [is this all of your code?] Yes it is.

    I have a question about the void main(). Why shouldn't you use it this way? I have advanced C++ now and the instructor teaches us to do it this way. However in my visual c++ class, my instructor taught us to use int main (). Is there a right or wrong here or just preference?

  5. #5
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    void main() is non-standard. Either int main() or int main(int argc, char *argv[]) are acceptable, and standard.

    Also, check here: http://www.cprogramming.com/boardfaq.html#main

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    5
    Why so many braces? The reason I used this line, for (int x = 0; x<=100; ++x); was to make the score greater than 0 but this than 100.

    I see this is wrong, what way should I code this?

  7. #7
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    >Why so many braces?

    Just my style... it catches needless mistakes.

    >for (int x = 0; x<=100; ++x); was to make the score greater than 0 but this than 100.

    >I see this is wrong, what way should I code this?

    Sorry, I have no idea what you're trying to do there. What do you want to make more than 0 but less than 100? I think your logic is a little off, this should be an if statement. like if (number < 0) number = 0; if (number > 100) number = 100;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21