Моя программа игнорирует оператор switch. Когда я запускаю его, я ввожу свой ввод, и он просто переходит к умолчанию, в котором говорится «Недействительный ответ». Что бы я ни вводил, он идет по умолчанию, полностью игнорируя случаи оператора switch. Я проверил код, и он выглядит совершенно нормально.Почему моя программа игнорирует оператор switch?
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdio.h>
using namespace std;
void ave();
void lar();
void sma();
void med();
void sorta();
void sortd();
int n;
int n1;
int n2;
int n3;
int n4;
int n5;
int n6;
int n7;
int n8;
int n9;
int n10;
int list[10] = {n1, n2, n3, n4, n5, n6, n7, n8, n9, n10};
int av;
int la;
int sm;
int me;
int sa;
int sd;
bool wayToSort(int i, int j) { return i > j; };
int main()
{
int c;
char q;
cout<< "Enter the first integer";
cin>> n1;
cout<< "Enter the second integer";
cin>> n2;
cout<< "Enter the third integer";
cin>> n3;
cout<< "Enter the fourth integer";
cin>> n4;
cout<< "Enter the fifth integer";
cin>> n5;
cout<< "Enter the sixth integer";
cin>> n6;
cout<< "Enter the seventh integer";
cin>> n7;
cout<< "Enter the eighth integer";
cin>> n8;
cout<< "Enter the ninth integer";
cin>> n9;
cout<< "Enter the tenth integer";
cin>> n10;
cout<< "1 - If you wish to find the average of the integers, press 1 \n";
cout<< "2 - If you wish to find the largest integer, press 2 \n";
cout<< "3 - If you wish to find the smallest integer, press 3 \n";
cout<< "4 - If you wish to find the median number, press 4 \n";
cout<< "5 - If you wish to sort the integers in ascending order, press 5 \n";
cout<< "6 - If you wish to sort the integers in descending order, press 6 \n";
//c = getchar();
cin>> c;
switch (c)
{
case '1':
ave();
break;
case '2':
lar();
break;
case '3':
sma();
break;
case '4':
med();
break;
case '5':
sorta();
break;
case '6':
sortd();
break;
default:
cout<< "Invaid choice";
return 0;
}
void ave();
{
av = (n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9 + n10) /10;
cout<< "The average of the numbers is " << av << endl;
}
void lar();
{
la = n1;
if (n2 > la)
la = n2;
else if (n3 > la)
la = n3;
else if (n4 > la)
la = n4;
else if (n5 > la)
la = n5;
else if (n6 > la)
la = n6;
else if (n7 > la)
la = n7;
else if (n8 > la)
la = n8;
else if (n9 > la)
la = n9;
else if (n10 > la)
la = n10;
cout<< "The largest integer is " << la << endl;
}
void sma();
{
sm = n1;
if (n2 < sm)
sm = n2;
else if (n3 < sm)
sm = n3;
else if (n4 < sm)
sm = n4;
else if (n5 < sm)
sm = n5;
else if (n6 < sm)
sm = n6;
else if (n7 < sm)
sm = n7;
else if (n8 < sm)
sm = n8;
else if (n9 < sm)
sm = n9;
else if (n10 < sm)
sm = n10;
}
void med();
{
sort(list, list + 10);
for (size_t i = 0; i != 10; ++i)
me = 0.5 * (list[n/2] + list[n/2-1]);
}
void sorta();
{
sort(list, list + 10);
cout<< "The sorted array looks like this " << endl;
for (size_t i = 0; i != 10; ++i)
cout<< list[i] << " ";
}
void sortd();
{
vector<int> intVec = { n1, n2, n3, n4, n5, n6, n7, n8, n9, n10};
sort(intVec.begin(), intVec.end(), wayToSort);
for (int i : intVec)
cout<< i << " ";
}
cout<< "\n Quit (y/n)";
cin>> q;
q = getchar();
}
c - целое число. не используйте цитаты –
... или не делайте 'c' a' char', а не 'int'. –