Hello, im trying to create a menu where there should be different options, for example converting roman to normal numbers. Im not very good at programming so I need some help. I have combined 2 different programmes that work by themselves but dosent work together. Will someone please help me? :)
#include <iostream>
#include <string>
using namespace std;
int main()
{
int menyval;
bool fortsatt = true;
do
{
cout << " 1 - Tabell Romerska siffror.\n";
cout << " 2 - Omvandla romerska siffror\n";
cout << " 3 - mllmml.\n";
cout << " 4 - Avsluta.\n";
cout << " Enter your choice and press return: ";
cin >> menyval;
switch (menyval)
{
case 1:
cout << "...\n";
int value(char roman)
{ //Here's where the problem is
switch (roman)
{
case 'I':return 1;
case 'V':return 5;
case 'X':return 10;
case 'L':return 50;
case 'C':return 100;
case 'D':return 500;
case 'M':return 1000;
}
}
//Function to convert Roman Numerals to Integer
int romanToInt(string A)
{
int i, n, ans = 0, p = 0;
n = A.length() - 1;
for (i = n; i >= 0; i--)
{
if (value(A[i]) >= p)
ans = ans + value(A[i]);
else
ans = ans - value(A[i]);
p = value(A[i]);
}
return ans;
}
//Main Function
int main() {
string s;
int num;
cin >> s;
num = romanToInt(s);
cout << num << "\n";
}
break; //You can ignore the rest if u want, just wanted to show the full picture.
case 2:
cout << "Ange ett romerskt tal\n";
break;
case 3:
cout << "Deluppgift 2\n";
// rest of code here
break;
case 4:
cout << "End of Program.\n";
fortsatt = false;
break;
default:
cout << "Not a Valid Choice. \n";
cout << "Choose again.\n";
cin >> menyval;
break;
}