need function help

I am writing a program project for class and having difficulties with creating a value returning function that reads in a integer value, takes that value compares it in array of words then takes these words from the array and stores it in a string. I believe if it will run it should return the string value,
but now my program will not even compile.

here is the fuction prototype, header and function call that I have written:


string convertDollars(int); // prototype NOTE: this is on Line 19


CvtDollars = convertDollars(ChkDollars); // "convertDollars" functioncall


string convertDollars(int ChkDollars) //function header
{


my functions code in here..


}

i believe the complier doesnt like something to do with the way i have written these.. this is the error i get below when I try to Build..the error seems to associate where i have the prototype for my function listed..

1>------ Build started: Project: project4, Configuration: Debug Win32 ------
1> project4.cpp
1>c:\users\neo\documents\visual studio 2010\projects\project4\project4\project4.cpp(19): error C2146: syntax error : missing ';' before identifier 'convertDollars'
1>c:\users\neo\documents\visual studio 2010\projects\project4\project4\project4.cpp(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\neo\documents\visual studio 2010\projects\project4\project4\project4.cpp(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int


" There are alot more errors here when I build, but they seems to be because of the the ones i have listed."

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Seeing the whole code would help greatly. What you've asked is the equivalent of "Fill in the missing words: How much <> <> <> <> chuck <> a <> <> chuck <>"

Having said that, you could put a std:: in front of all the strings.

Cheers,
Jim
Last edited on
Thanks Jim, that worked but i didnt think it was needed, for some reason I thought visual studio added it in.. I guess i dont understand why that worked?
If you put the following line somewhere near the top of your file (after #include <iostream>), you'll not need the std:: in front of the strings.

using namespace std;

It's because you need to tell the compiler where everything is - absolutely everything. If you remember that the compiler is generally incapable of intelligent thought, and spell everything out to it, generally you'll be OK.

Jim
I found the error of my ways:


I had it written like this:


#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
#include<cstdlib>


string convertDollars(int ); //Convert dollars to words - function prototype


using namespace std;


when it should have been written like this:


#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
#include<cstdlib>


using namespace std;


string convertDollars(int );
//Convert dollars to words - function prototype
Topic archived. No new replies allowed.