Error C2360

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

std::string numerals = "MDCLVX";

int main()
{
int choice;
bool On = true;
while (On != false)
{
cout << endl;
cout << " 1 - Omvandla romersk siffra till arabisk siffra.\n";
cout << " 2 - Omvandla arabisk siffra till romersk siffra.\n";
cout << " 3 - Exit.\n";
cout << " Enter your choice and press return: ";

cin >> choice;

switch (choice)
{
case 1:

char romersk_nummer;
int nummer = 0;

cout << "Skriv in ett Romersk nummer (t.ex CCXIX) : ";
while (cin.get(romersk_nummer))
{
if (romersk_nummer == 'M')
nummer = nummer + 1000;

else if (romersk_nummer == 'D')
{
romersk_nummer = cin.peek();
if (numerals.find(romersk_nummer, 5) != std::string::npos)
{
nummer = nummer - 500;
continue;
}
else
{
nummer = nummer + 500;
continue;
}
}

else if (romersk_nummer == 'C')
{
romersk_nummer = cin.peek();
if (numerals.find(romersk_nummer, 4) != std::string::npos)
{
nummer = nummer - 100;
continue;
}
else
{
nummer = nummer + 100;
continue;
}
}

else if (romersk_nummer == 'L')
{
romersk_nummer = cin.peek();
if (numerals.find(romersk_nummer, 3) != std::string::npos)
{
nummer = nummer - 50;
continue;
}
else
{
nummer = nummer + 50;
continue;
}
}

else if (romersk_nummer == 'X')
{
romersk_nummer = cin.peek();
if (numerals.find(romersk_nummer, 2) != std::string::npos)
{
nummer = nummer - 10;
continue;
}
else
{
nummer = nummer + 10;
continue;
}
}

else if (romersk_nummer == 'V')
{
romersk_nummer = cin.peek();
if (numerals.find(romersk_nummer, 1) != std::string::npos)
{
nummer = nummer - 5;
continue;
}
else
{
nummer = nummer + 5;
continue;
}
}

else if (romersk_nummer == 'I')
{
romersk_nummer = cin.peek();
if (numerals.find(romersk_nummer) != std::string::npos)
{
nummer = nummer - 1;
continue;
}
else
{
nummer = nummer + 1;
continue;
}
}
else
{
cout << "Det du angett är ogiltigt";

}
cout << nummer << endl;

break;

case 2:
int num;
cout << "Ange ett vanligt nummer: ";
cin >> num;
while (num > 0)
{
if (num >= 1000)
{
cout << "M";
num -= 1000;
}
else if (num >= 900)
{
cout << "CM";
num -= 900;
}
else if (num >= 500)
{
cout << "D";
num -= 500;
}
else if (num >= 400)
{
cout << "CD";
num -= 400;
}
else if (num >= 100)
{
cout << "C";
num -= 100;
}
else if (num >= 90)
{
cout << "XC";
num -= 90;
}
else if (num >= 50)
{
cout << "L";
num -= 50;
}
else if (num >= 40)
{
cout << "XL";
num -= 40;
}
else if (num >= 10)
{
cout << "X";
num -= 10;
}
else if (num >= 9)
{
cout << "IX";
num -= 9;
}
else if (num >= 5)
{
cout << "V";
num -= 5;
}
else if (num >= 4)
{
cout << "IV";
num -= 4;
}
else if (num >= 1)
{
cout << "I";
num -= 1;
}
}

break;
case 3:
cout << "End of Program.\n";
On = false;
break;
default:
cout << "Not a Valid Choice. \n";
cout << "Choose again.\n";
cin >> choice;
break;
}

}


return 0;
}
}

How should i fix this error. It keep skipping nummer.
Put everything after case ...: until break; inside curly braces {}. E.g.

1
2
3
4
5
6
7
case 1:
{
  char romersk_nummer;
  int nummer = 0;
..
}
break;
The missing format makes it hard to read your code...

Actually you need curly braces for all switch cases where you have local variables. Thus case 2: lacks this braces as well.
Topic archived. No new replies allowed.