Hey, im doing a project for class and I have to convert a user entered number into roman numerals. I have 3 criteria to meet
1. read the conversion data from file into an array
2. have a loop that allows the user to continue entering numbers until an end sentinel such as 0 is entered.
3. create a user-defined function that takes arguments of an integer ( between 1-20) , as well as the data conversion array and its size. The function will return or display the corresponding Roman numeral.
I think I have the logic down but im getting errors when I try to pass the "string array" into my function. Im really stuck, can anyone shed some light?
string numeralArray[19];
string line;
string infile;
int userNum = 1;
int size = 1;
int start = 1;
ifstream file("Homework2.txt");
if (file.is_open())
{
for (int i = 0; i < 5; ++i)
{
file >> numeralArray[i];
}
cout << numeralArray[3] << endl;
while (userNum != 0)
{
cout << " Enter a number between 1-20 or 0 to exit" << endl;
cin >> userNum;
if (userNum != 0)
{
display(numeralArray, userNum);
}
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
void display(string array[], int num);
int main()
{
string numeralArray[19];
string line;
string infile;
int userNum = 1;
ifstream file("Homework2.txt");
if (file.is_open())
{
for (int i = 0; i < 5; ++i)
{
file >> numeralArray[i];
}
cout << numeralArray[3] << endl;
while (userNum != 0)
{
cout << " Enter a number between 1-20 or 0 to exit" << endl;
cin >> userNum;
//this if statement is useless. condition already checked by while loop
if (userNum != 0)
{
display(numeralArray, userNum);
}
}
system("pause");
return 0;
}
}
void display(string array[], int num)
{
cout << "\n" << array[num] << "\n";
}
Since I don't have the file and its contents, as far as I can tell your code is correct.
The error you're getting is line 36 "display is not declared in this scope". You have a function prototype and a function definition, but the latter is empty.
thanks for the reply! the text file is just roman numerals, I know what to do inside the function but didnt fill it out yet. I was getting these error messages
E0308 more than one instance of overloaded function "display" matches the argument list: 38
Error C2065 'string': undeclared identifier 5
Error C2146 syntax error: missing ')' before identifier 'array' 5 C3861 'display': identifier not found 38
> E0308 more than one instance of overloaded function "display" matches the argument list: 38
> Error C2065 'string': undeclared identifier 5
Well in your first code, the first problem is your prototype is BEFORE your using namespace.
Also, 'display' is such a common word that it could well be defined somewhere in your header files, leading to the "more than one instance" problem.