Hi Everyone,
I'm writing a calculator program and when I compile I get the following error code.
Expected primary expression before ';' token (which is line 57)
This is a work in progress and is not finished but I would like to run it to check my menu navigation. The program will run but it I cant select the menu option I would like. When I do select another option in the menu I get the correct submenu title, but it will continue with the first menu option regardless of the choice made.
To clarify the following is what I'm intending to happen:
1. The main menu will show up wit the 8 options using cout
2. Prompt user for a selection and have a cin to the int mainchoice variable.
3. The switch (mainchoice) then will cout the menu title chosen by the user (ie if the user presses 1, it will show up the first option in the menu).
4. After the switch (mainchoice), the if statement if (mainchoice = 1) will check if the input was 1 or not, if the input was 1, continue to sub routine for 4-20mA. If the input was not 1, move down to the if (mainchoice = 2) and if the input was two continue to sub routine for flow calculations.
Above is how the menu should work however when I select any option (1-8) I get the submenu title come up but then it runs the 4-20mA sub routine anyway.
I'm trying to use a nested if here, and I don't think I have done it right.
Any help on either of the above issues would be great.
Thank you in advance.
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;
int main()
{
//Assigning variables
int mainchoice = 0; //menu option
//4-20mA Sub Routine
string engunit;
float marange = 0;
float currentma = 0;
float scaledval = 0;
int maorscaled = 0;
float ans1 =0;
float ans1a = 0;
float ans2 =0;
double ans2a = 0; //NOT WORKING AT PRESENT
//Flow Sub Routine
int engunita = 0;
int engunitb = 0;
float flowval1 = 0;
//Flow Tags
float lpstolpm = 0;
float lpstolph = 0;
float lpstomcph = 0;
float lpstomcpd = 0;
float lpstomld = 0;
float lpmtolps = 0;
float lpmtolph = 0;
float lpmtomcph = 0;
float lpmtomcpd = 0;
float lpmtomld = 0;
float lphtolps = 0;
float lphtolpm = 0;
float lphtomcph = 0;
float lphtomcpd = 0;
float lphtomld = 0;
cout << " Main Menu\n\n";
cout << "\t\t1 - 4-20mA\n";
cout << "\t\t2 - Flow\n";
cout << "\t\t3 - \n";
cout << "\t\t4 - \n";
cout << "\t\t5 - \n";
cout << "\t\t6 - \n";
cout << "\t\t7 - \n";
cout << "\t\t8 - \n";
cout << "\n Please select which calculator: ";
cin >> mainchoice;
switch (mainchoice)
{
case 1: cout << "\n4-20mA\n\n\n";
break;
case 2: cout << "\nFlow.\n";
break;
case 3: cout << "\nTime.\n";
break;
case 4: cout << "\nOvercurrent i2t.\n";
break;
case 5: cout << "\nCT Wire Size.\n";
break;
case 6: cout << "\nWet Well Volume.\n";
break;
case 7: cout << "\nPercentage.\n";
break;
case 8: cout << "\nThree Phase.\n";
break;
default: cout << "\nInvalid Response.\n";
}
if(mainchoice = 1)
{ //Sub routine for 4-20mA
cout << "Please enter an engneering unit: ";
cin >> engunit;
cout << "\nPlease enter the range of the instrument: ";
cin >> marange;
cout << "\nChoose to enter either a milliamp reading or scaled"
<< " value, make your choice.\n\n\t\t1. Milliamp reading.\n\t\t2. Scaled Value\n";
cin >> maorscaled;
switch (maorscaled)
{
case 1: cout << "Please enter a Milliamp Reading:";
cin >> currentma;
cout << "\nCalculating scaled value if mA reading is" << currentma <<" for you\n";
ans1a = marange / 16; //this will equal 6.25 for 100
ans1 = ans1a * (currentma-4);
cout << "\nThe scaled value would be" << ans1 << engunit <<" for a given milliamp input of" << currentma <<".\n\n";
break;
case 2: cout << "Please enter a Scaled Value:";
cin >> scaledval;
cout << "Calculating mA reading if scaled value is\n" << scaledval <<" for you\n";
ans2 = marange / 16;
ans2a = scaledval / (ans2+4); //* 10);
cout << "The scaled value would be" << std::setprecision(4) << ans2a << "mA for a scaled value of" << scaledval << ".\n\n";
break;
default: cout << "Invalid Response";
}
if (mainchoice = 2)
{//Sub routine for Flow calculations
cout << "\t\tPlease choose an engineering unit\n\n";
cout << "\t\t1: Litres per second ( L/s )\n";
cout << "\t\t2: \n";
cout << "\t\t3: \n";
cout << "\t\t4: \n";
cout << "\t\t5: \n";
cout << "\t\t6: \n";
cin >> engunita;
switch (engunita)
{
case 1: cout << " Please enter a L/s reading:";
cin >> flowval1;
lpstolpm = flowval1 * 60;
lpstolph = flowval1 * 3600;
lpstomcph = flowval1 * 3.6;
lpstomcpd = flowval1 * 86.4;
lpstomld = flowval1 * 0.0864;
cout << "\n "<< flowval1 <<" = " << lpstolpm <<"L/min";
cout << "\n "<< flowval1 <<" = " << lpstolph <<"L/hour";
cout << "\n "<< flowval1 <<" = " << lpstomcph <<"m3/h";
cout << "\n "<< flowval1 <<" = " << lpstomcpd <<"m3/d";
cout << "\n "<< flowval1 <<" = " << lpstomld <<"ML/D";
break;
case 2: cout << " Please enter a L/m reading:";
cin >> flowval1;
lpmtolps = flowval1 / 60;
lpmtolph = flowval1 * 60;
lpmtomcph = flowval1 * 0.06;
lpmtomcpd = flowval1 * 1.44;
lpmtomld = flowval1 * 0.00144;
cout << "\n "<< flowval1 <<" = " << lpmtolps <<"L/sec";
cout << "\n "<< flowval1 <<" = " << lpstolph <<"L/hour";
cout << "\n "<< flowval1 <<" = " << lpstomcph <<"m3/h";
cout << "\n "<< flowval1 <<" = " << lpstomcpd <<"m3/d";
cout << "\n "<< flowval1 <<" = " << lpstomld <<"ML/D";
break;
case 3: cout << " Please enter a L/h reading:";
cin >> flowval1;
lphtolps = flowval1 * 60;
lphtolpm = flowval1 * 3600;
lphtomcph = flowval1 * 3.6;
lphtomcpd = flowval1 * 86.4;
lphtomld = flowval1 * 0.0864;
cout << "\n "<< flowval1 <<" = " << lphtolps <<"L/sec";
cout << "\n "<< flowval1 <<" = " << lpstolpm <<"L/hour";
cout << "\n "<< flowval1 <<" = " << lpstomcph <<"m3/h";
cout << "\n "<< flowval1 <<" = " << lpstomcpd <<"m3/d";
cout << "\n "<< flowval1 <<" = " << lpstomld <<"ML/D";
break;
default:cout << "Invalid Reponse" <<;
}
}
else
{
}
}
cout << "\n\n\n\nPress any key to continue.\n";
getch();
return 0;
}
|