Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,376 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,152 people online right now. Registration is fast and FREE... Join Now!




C++ calling 2 functions to main

 
Reply to this topicStart new topic

C++ calling 2 functions to main, calling 2 functions to main,1 sums digits, 2nd tells if odd or even in

josiclown
post 24 Oct, 2006 - 08:49 PM
Post #1


New D.I.C Head

*
Joined: 24 Oct, 2006
Posts: 1


My Contributions


I've been struggling withthis since 4 pm today(it is now 12:30 am) so, any help would be appreciated. I've tried this 10 ways from yesterday.

Here is what I have, below code you will see the error messages.

josiclown

CODE


#include<iostream>
using namespace std;
int Num, x, Y,;
void OddEven(char Odd, char Even);
int SumOfDigits(int x);
char Odd, Even;


int main()
{
  system("cls"); // this clears the output screen
  do
  {
   cout << "Enter an integer--> ";
   cin >> Num;

   if ((Num >= 1) && (Num <= 100))
   {
       OddEven();
      
       int SumOfDigits();
      
    

   }
   while (Num != 0);
}

/************************Odd/Even*************************
Action: Determines if integer entered is odd or even.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void OddEven(char Odd, char Even)
{
  if (Num % 2 == 0)
   {
    cout << "Integer " Num << " is even" << endl;
    return (Even);
   }

else
    cout << "integer " Num << " is odd" << endl;
  return (Odd);
}
/*************************SumInteger**************************
Action: Sums user entered intger, but, sums all the digits of
the number and displays on the main.************************/


int SumOfDigits(int x)
{
int i, Sum;
Sum=0;
i=x;
for((i!=0) && (i=i%10))
Sum+=i%10;
cout << "Sum of the digits of + << Num << "is " << Sum << endl;

}


ERRORS:

QUOTE
------ Rebuild All started: Project: OddEven, Configuration: Debug Win32 ------

Deleting intermediate files and output files for project 'OddEven', configuration 'Debug|Win32'.
Compiling...
Hmwk7-2.cpp
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(3) : error C2059: syntax error : ';'
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(19) : error C2660: 'OddEven' : function does not take 0 arguments
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(32) : error C2062: type 'void' unexpected
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(33) : error C2143: syntax error : missing ';' before '{'
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(36) : error C2146: syntax error : missing ';' before identifier 'Num'
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(36) : error C2297: '<<' : illegal, right operand has type 'const char [9]'
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(36) : error C2563: mismatch in formal parameter list
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(36) : error C2568: '<<' : unable to resolve function overload
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(928): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=wchar_t,
_Traits=std::char_traits<wchar_t>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(920): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(896): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(41) : error C2146: syntax error : missing ';' before identifier 'Num'
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(41) : error C2297: '<<' : illegal, right operand has type 'const char [8]'
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(41) : error C2563: mismatch in formal parameter list
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(41) : error C2568: '<<' : unable to resolve function overload
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(928): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=wchar_t,
_Traits=std::char_traits<wchar_t>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(920): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(896): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(50) : error C2601: 'SumOfDigits' : local function definitions are illegal
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(56) : error C2001: newline in constant
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(59) : fatal error C1075: end of file found before the left brace '{' at 'c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(10)' was matched

Build log was saved at "file://c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Debug\BuildLog.htm"
OddEven - 15 error(s), 0 warning(s)


This post has been edited by Dark_Nexus: 24 Oct, 2006 - 09:14 PM
User is offlineProfile CardPM

Go to the top of the page

dragonlady
post 24 Oct, 2006 - 09:01 PM
Post #2


D.I.C Head

**
Joined: 7 Aug, 2005
Posts: 57


My Contributions


The problem I see is that you declared a function OddEven() that takes 2 integers as arguments, but then you call the function in main() with no arguments. That's probably causing a few of your errors. Fix that and see if it works out.
User is offlineProfile CardPM

Go to the top of the page

gregoryH
post 25 Oct, 2006 - 12:21 AM
Post #3


D.I.C Regular

Group Icon
Joined: 4 Oct, 2006
Posts: 417



Dream Kudos: 50
My Contributions


QUOTE(josiclown @ 24 Oct, 2006 - 09:49 PM) *

I've been struggling withthis since 4 pm today(it is now 12:30 am) so, any help would be appreciated. I've tried this 10 ways from yesterday.

Here is what I have, below code you will see the error messages.

josiclown


CODE

#include<iostream>
using namespace std;
int Num, x, Y,;
void OddEven(char Odd, char Even);
int SumOfDigits(int x);
char Odd, Even;


ERRORS:

QUOTE
------ Rebuild All started: Project: OddEven, Configuration: Debug Win32 ------
Projects\OddEven\OddEven\Hmwk7-2.cpp(3) : error C2059: syntax error : ';'
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OddEven\OddEven\Hmwk7-2.cpp(19) : error C2660: 'OddEven' : function does not take 0 arguments


Josi

First error - the compiler told you line(3).... yes.. the number in the brackets is the line where the compiler found an error....

int Num, x, Y,;<<-- there is something between the Y and the ;. The messager actually indicates it was expecting the next variable, so the ; was the cause of the throw

Line 19 - see dragon lady's suggestion smile.gif

This post has been edited by gregoryH: 25 Oct, 2006 - 12:56 AM
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 06:12AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month