Void Function
Nov 20, 2021 at 7:05am UTC
I declared a void function but when I tried to call it inside a switch statement it would not show up. Does anybody know what mistake I did? I only want to figure out how the void function would appear in the case statement thank you!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int rowlimit = 10;
string ar_id [rowlimit] = {};
string ar_name [rowlimit] = {};
string ar_price [rowlimit] = {};
string ar_quantity [rowlimit] = {};
void ADDITEM ()
{cout << "\t\t\t\t\t\t\b\b\b\b\b\b\b\bID: " ;
cin.getline(id, 100);
cout << "\t\t\t\t\t\t\b\b\b\b\b\b\b\bNAME: " ;
cin.getline(name, 100);
cout << "\t\t\t\t\t\t\b\b\b\b\b\b\b\bPRICE: " ;
cin.getline(price, 100);
cout << "\t\t\t\t\t\t\b\b\b\b\b\b\b\bQUANTITY: " ;
cin.getline(quantity, 100);
for (int x = 0; x < rowlimit; x++)
{
if (ar_id[x] == "\0" )
{
ar_id [x] = id;
ar_name [x] = name;
ar_price [x] = price;
ar_quantity [x] = quantity;
break ;
}
}
}
int main(){
std :: cout << "MENU\n" ;
int optionnum; menu
system ("clear" );
do {
cout << "\n ---------------------------------------------------------------------------------------------" << endl;
cout << "\t\t\t\t\t\t\b\b\b\b\bMAIN MENU" << endl;
cout << " ---------------------------------------------------------------------------------------------" << endl; //print the output
cout << "\t\t\t\t\t\t\b\b\b\b\b\b\b\b[1] - Book a Ticker" << endl;
cout << "\t\t\t\t\t\t\b\b\b\b\b\b\b\b[2] - Update Information" << endl;
cout << "\t\t\t\t\t\t\b\b\b\b\b\b\b\b[3] - Cancel a reservation" << endl;
cout << "\t\t\t\t\t\t\b\b\b\b\b\b\b\b[4] - Show price list" << endl;
cout << "\t\t\t\t\t\t\b\b\b\b\b\b\b\b[5] - Go back" << endl;
cout << " ---------------------------------------------------------------------------------------------" << endl;
cout << "\n\v\tPick a Number from the Items Above: " ;
cin >> optionnum;
switch (optionnum)
{
case '1' : ADDITEM ();
system ("clear" );
break ;
}
} while (optionnum != 6);
return 0;
}
Last edited on Nov 20, 2021 at 7:09am UTC
Nov 20, 2021 at 7:24am UTC
line 58: The problem is your case label, not your function call.
Your case label is '1'. That is an ASCII character. optionnum is an int.
The line should be:
Line 27:
is preferred to testing for a null character.
Last edited on Nov 20, 2021 at 7:27am UTC
Topic archived. No new replies allowed.