Basically, the function "int invalidInputs (bool = true)", must utilize it's own counter to keep track of the total amount of times, the user entered an invalid input at the main menu of the program (not enter a b c d, or, q.
Then the Main function must call "invalidInputs (bool = true)" function, to aid in the output of a final message to the user, that includes the the total amount of times that he/she attempted an invalid input at the main menu.
I have put in comment's my attempts at trying to do this. Which resulted in an error message from Visual Studio stating "'invalidInputs': identifier not found"
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
const double PI = 3.14;
void mainMenu (char &);
double area (double, double);
double area (double r);
double volume (double, double, double);
double volume (double r);
//int invalidInputs ();
int main()
{
char choice;
//int Count = 0;
//int totalCount;
//totalCount += Count;
double l, w, h, r;
do {
mainMenu(choice);
if (choice != 'q')
{
if (choice == 'a')
{
do {
cout << "Enter l: ";
cin >> l;
} while (l < 0 );
do {
cout << "Enter w: ";
cin >> w;
} while (w < 0);
cout << "Area of rectangle: " << area(l, w) << endl;
cout << "" << endl;
}
else if (choice == 'b')
{
do {
cout << "Enter r: ";
cin >> r;
} while (r < 0 );
//total = area(r);
cout << "Area of circle: " << area(r) << endl;
cout << "" << endl;
}
else if (choice == 'c')
{
do {
cout << "Enter l: ";
cin >> l;
} while (l < 0 );
do {
cout << "Enter w: ";
cin >> w;
} while (w < 0);
do {
cout << "Enter h: ";
cin >> h;
} while (h < 0);
cout << "Area of box: " << volume(l, w, h) << endl;
cout << "" << endl;
}
else if (choice == 'd')
{
do {
cout << "Enter r: ";
cin >> r;
} while (r < 0 );
cout << "Area of sphere: " << volume(r) << endl;
cout << "" << endl;
}
}
else //when user quits
{
//cout << "Have a good day. " << endl << " There were " << invalidInputs(totalCount) << " invalid inputs." << endl;
cout << "Have a good day. " << endl; //RUN without checking for total invalid inputs.
}
}
while (choice != 'q');
system ("pause");
return 0;
}
void mainMenu (char &choose)
{
//int countError = 0;
//bool invalid;
cout << "a to calculate area of a rectangle" << endl;
cout << "b to calculate area of a circle" << endl;
cout << "c to calculate volume of a box" << endl;
cout << "d to calculate volume of sphere" << endl;
cout << "q to quit" << endl;
cin >> choose;
while (choose != 'a' && choose != 'b' && choose != 'c' && choose != 'd' && choose != 'q')
{
//invalid = true;
//int invalidInputs (invalid);
cout << "Invalid choice" << endl;
cout << "";
cout << "press a to calculate area of a rectangle" << endl;
cout << "b to calculate area of a circle" << endl;
cout << "c to calculate volume of a box" << endl;
cout << "d to calculate volume of sphere" << endl;
cout << "q to quit" << endl;
cin >> choose;
}
}
double area (double l, double w) //Selection A
{
return l * w;
}
double area (double r) //B
{
return pow(PI * r, 2);
}
double volume (double l, double w, double h) //C
{
return l * w * h;
}
double volume (double r) //D
{
return 4/3 * PI * pow(r, 3);
}
/*
int invalidInputs (bool = true)
{
int Count = 0;
int totalCount;
bool invalid;
if (invalid == true){
Count++;
totalCount += Count;
}
else {
totalCount += Count ;
}
return totalCount;
} */

New Topic/Question
Reply



MultiQuote






|