#include <iostream>
#include <string>
using namespace std;
enum month {one, two, three, four, five, six, seven, eight, nine, ten};
const char monthname[][10] = {"one","two","three","four","five","six","seven","eight","nine","ten"};
enum ggg {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const char monthnameg[][10] = {"1","2","3","4","5","6","7","8","9","10"};
int main()
{
string input;
month course;
ggg gfg;
cout<<"Enter a number 1-10 or in words eg. one,two,three ect.: ";
cin >> input;
if(input == "one" || input == "two" || input =="three" || input == "four" || input == "five" || input =="six" ||input == "seven" || input == "eight" || input =="nine" || input == "ten" )
{
for(int i = 0; i < 11; i++)
{
if(input == monthname[i])
{
course = (month)i;
break;
}
}
switch(course)
{
case one:
cout<<"\n The roman numeral for one is I";
break;
case two:
cout<<"\n The roman numeral for two is II";
break;
case three:
break;
cout<<"\n The roman numeral for three is III";
case four:
cout<<"\n The roman numeral for four is IV";
break;
case five:
cout<<"\n The roman numeral for five is V";
break;
case six:
cout<<"\n The roman numeral for six is VI";
break;
case seven:
cout<<"\n The roman numeral for seven is VII";
break;
case eight:
cout<<"\n The roman numeral for eight is VIII";
break;
case nine:
cout<<"\n The roman numeral for nine is IX";
break;
case ten:
cout<<"\n The roman numeral for ten is X";
break;
} // close switch block
} //close if
else
{
for(int j = 0; j < 11; j++)
{
if(input == monthnameg[j])
{
gfg = (ggg)j;
break;
}
}
switch(gfg)
{
case 1:
cout<<"\n The roman numeral for 1 is I";
break;
case 2:
cout<<"\n The roman numeral for 2 is II";
break;
case 3:
break;
cout<<"\n The roman numeral for 3 is III";
case 4:
cout<<"\n The roman numeral for 4 is IV";
break;
case 5:
cout<<"\n The roman numeral for 5 is V";
break;
case 6:
cout<<"\n The roman numeral for 6 is VI";
break;
case 7:
cout<<"\n The roman numeral for 7 is VII";
break;
case 8:
cout<<"\n The roman numeral for 8 is VIII";
break;
case 9:
cout<<"\n The roman numeral for 9 is IX";
break;
case 10:
cout<<"\n The roman numeral for 10 is X";
break;
} // close switch block
}//end of else
return 0;
}// end of main
Why wont it work
Started by dvdtomkins, May 19 2008 03:29 AM
7 replies to this topic
#1
Posted 19 May 2008 - 03:29 AM
Can anybody please tell me why this code wont compile
|
|
|
#2
Posted 19 May 2008 - 11:42 AM
Enumeration constants are symbolic names for values. Compare
enum month {[COLOR="Blue"]one[/COLOR], [COLOR="Blue"]two[/COLOR], [COLOR="Blue"]three[/COLOR], [COLOR="Blue"]four[/COLOR], [COLOR="Blue"]five[/COLOR], [COLOR="Blue"]six[/COLOR], [COLOR="Blue"]seven[/COLOR], [COLOR="Blue"]eight[/COLOR], [COLOR="Blue"]nine[/COLOR], [COLOR="Blue"]ten[/COLOR]};
withenum ggg {[COLOR="Red"]1[/COLOR], [COLOR="Red"]2[/COLOR], [COLOR="Red"]3[/COLOR], [COLOR="Red"]4[/COLOR], [COLOR="Red"]5[/COLOR], [COLOR="Red"]6[/COLOR], [COLOR="Red"]7[/COLOR], [COLOR="Red"]8[/COLOR], [COLOR="Red"]9[/COLOR], [COLOR="Red"]10[/COLOR]};
#3
Posted 19 May 2008 - 11:33 PM
So how do I make this program work?
#4
Posted 20 May 2008 - 02:37 AM
Found some help from a site and came up with this:
#include <iostream>
#include <string>
using namespace std;
const int SIZE = 10;
string num1[SIZE] = {"one", "two", "three","four","five","six","seven","eight","nine","ten"};
string roman1[SIZE] = {"I", "II", "III","IV","V","VI","VII","VIII","IX","X"};
string num2[SIZE] = {"1", "2", "3","4","5","6","7","8","9","10"};
string roman2[SIZE] = {"I", "II", "III","IV","V","VI","VII","VIII","IX","X"};
int main()
{
string input;
cout<<"Enter a number 1-10 or in words eg. one,two,three ect.: ";
cin >> input;
if(input == "one" || input == "two" || input =="three" || input == "four" || input == "five" || input =="six" ||input == "seven" || input == "eight" || input =="nine" || input == "ten" )
{
for(int i = 0; i < SIZE; ++i)
{
if(num1[i] == input)
{
cout <<"The roman numeral for "<< num1[i] << " is " << roman1[i];
break;
}//close if
}//close for
} //close if
else
{
for(int i = 0; i < SIZE; ++i)
{
if(num2[i] == input)
{
cout <<"The roman numeral for "<< num2[i] << " is " << roman2[i];
break;
}//close if
}//close for
}//end of else
return 0;
}// end of main
#5
Posted 25 May 2008 - 07:58 AM
seriously lotsa error in that code..........check if there r arrays for STRINGS!!......and also check your char array declarations to name a few!!
Edited by cribtolearn, 25 May 2008 - 08:01 AM.
#6
Posted 29 May 2008 - 05:03 AM
Okay I was bored in school today and saw this code and decided to at least get it working. It's still kind of **** because I didn't feel like writing any type of conversion function, but it will do what you want it to and you can "make it better" if you want to. It will take numeric expressions and word expressions and do the roman numeral thing... Here.......
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
char input[100];
int int_input;
cout<<"Enter a number 1-10 or in words eg. one,two,three ect.: ";
cin >> input;
int_input = atoi(input);
if ((int_input > 0) && (int_input < 11)) {
switch(int_input) {
case 1:
cout<<"\nThe roman numeral for one is I";
break;
case 2:
cout<<"\nThe roman numeral for two is II";
break;
case 3:
cout<<"\nThe roman numeral for three is III";
break;
case 4:
cout<<"\nThe roman numeral for four is IV";
break;
case 5:
cout<<"\nThe roman numeral for five is V";
break;
case 6:
cout<<"\nThe roman numeral for six is VI";
break;
case 7:
cout<<"\nThe roman numeral for seven is VII";
break;
case 8:
cout<<"\nThe roman numeral for eight is VIII";
break;
case 9:
cout<<"\nThe roman numeral for nine is IX";
break;
case 10:
cout<<"\nThe roman numeral for ten is X";
break;
default:
cout << "\nINVALID AMOUNT";
break;
}
}
if (strcmp(input, "one") == 0) {
cout<<"\nThe roman numeral for one is I";
}
else if (strcmp(input, "two") == 0) {
cout<<"\nThe roman numeral for two is II";
}
else if (strcmp(input, "three") == 0) {
cout<<"\nThe roman numeral for three is III";
}
else if (strcmp(input, "four") == 0) {
cout<<"\nThe roman numeral for four is IV";
}
else if (strcmp(input, "five") == 0) {
cout<<"\nThe roman numeral for five is V";
}
else if (strcmp(input, "six") == 0) {
cout<<"\nThe roman numeral for six is VI";
}
else if (strcmp(input, "seven") == 0) {
cout<<"\nThe roman numeral for seven is VII";
}
else if (strcmp(input, "eight") == 0) {
cout<<"\nThe roman numeral for eight is VIII";
}
else if (strcmp(input, "nine") == 0) {
cout<<"\nThe roman numeral for nine is IX";
}
else if (strcmp(input, "ten") == 0) {
cout<<"\nThe roman numeral for ten is X";
}
getch();
return 0;
}// end of main
#7
Posted 30 May 2008 - 02:19 AM
I think your, missing a semicolon after a numeric constant in line 11 and a identifier as well as a '}' before numeric constant.
thats what my compiler says, hope it helps
thats what my compiler says, hope it helps
----Raven Studios----
-Programming Central-
-Programming Central-
#8
Posted 30 May 2008 - 03:02 AM
I'm missing those things? Because I'm pretty sure my code works...


Sign In
Create Account


Back to top









