hi guys. been a long time since i done some programming think it was delphi back about 5 years ago but trying out c++ now. anyway
i want to create a simple program but the menu thing baffles me
i was some error checking which i THINK is the CASE and SWITCH not sure tho.
anyway
i would like to loop the menu and if someone presses i.e. "1" they goto the 1 procedure and then back to the menu and hopefully continue this until they quit. "wasnt very good at loops etc"
here is the code ive done all of it myself and most likely its wrong but woudl like to learn lol so if someone can point me in the right direction it would be very much appreciated
Code:
#include <iostream>
using namespace std;
int menuchoice;
int januarymm;
int februarymm;
int totalmm;
void choice1()
{
cout << "january";
cin.get();
}
void choice2()
{
cout << "february";
}
void choice3()
{
cout << "total";
}
void choice4()
{
cout << "exit";
}
void main()
{
cout << " Rainfall Calculator by Nathan Hawthorne ";
cout << "\n";
cout << " 1. january Rainfall ";
cout << "\n";
cout << " 2. February Rainfall ";
cout << "\n";
cout << " 3. Total Rainfall ";
cout << "\n";
cout << " 4. Quit ";
cout << "\n";
cin >> menuchoice;
//************************************************************* error management
switch (menuchoice)
{
case '1':
case '2':
case '3':
case '4':
cout << " Selection OK ";
cin.get();
break;
default:
cout << " Invalid Selection\n";
cin.get();
break;
//************************************************************ error management
if (menuchoice = '1')
choice1();
if (menuchoice = '2')
choice2();
if (menuchoice = '3')
choice3();
if (menuchoice = '4')
choice4();
}
}