I have read and reread the chapter(s). I have used every thing I can think of (limited I admit) and all I seem do is change the error message from undeclared identifier to uninitialized local variable and back again. I know this is ugly and it probably doesn't work (once I get past this) but it is set up the way our instructor wants,
Any and all suggestions, remarks, assumptions, etc will be accepted with grace in the hopes that I will learn this (sooner rather than later) but this has given me a huge brain fart and all I do is keep looping the same conclusions over and over
Anyway. I am attempting to have the user enter a number and have the program return a roman numeral. I have tried char with several different names = "I" etc. and I have done "I" = several different names as well as int with variations and still it eludes me.
Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{ //this is were it all has fallen apart the following line. char gets me undeclared identifier and int is an undeclared local variable (when I change the variables in the other lines)
char a=I, b=II, c=III, d=IV, e=V, f=VI, g=VII, h=VIII, i=IX, j=X;
//I don't know if anything after works but I need to get there to work it. Any help to get beyond this point will be accepted and appreciated.
cout << "Please enter a number between one and ten. " << endl;
cin >> number;
if (number == num1)
{
cout << " The Roman Numeral for your number is: " << a << endl;
}
if (number == num2)
{
cout << " The Roman Numeral for your number is: " << b << endl;
}
if (number == num3)
{
cout << " The Roman Numeral for your number is: " << c << endl;
}
if (number == num4)
{
cout << " The Roman Numeral for your number is: " << d << endl;
}
if (number == num5)
{
cout << " The Roman Numeral for your number is: " << e << endl;
}
if (number == num6)
{
cout << " The Roman Numeral for your number is: " << f << endl;
}
if (number == num7)
{
cout << " The Roman Numeral for your number is: " << g << endl;
}
if (number == num8)
{
cout << " The Roman Numeral for your number is: " << h << endl;
}
if (number == num9)
{
cout << " The Roman Numeral for your number is: " << i << endl;
}
if (number == num10)
{
cout << " The Roman Numeral for your number is: " << j << endl;
}
else if (number <1 || >10);
{
cout << "Your number is incorrect " << num1 << endl;
}
return 0;
}
Maybe I can get down this end to see if it will work. Hey anythings possible!
Thanks for the time and trouble.
Kelly
When you say something like: char a = I;
You are making the variable 'a' be equal to the variable 'I'. Since you have no variable 'I', etc., you are getting errors. You probably wanted to create a character literal, like so: char a = 'I';
However you should note that a character is only one character. So "II" cannot be a character.
Thank You for your help. My instructor went over everything again this AM since I wasn't the only one emailing him. I really appreciate the effort and I'm sure I'll be back.