ok.. This a short menu im creating... it seem to be working prefectly fine other than the fact that it isnt showing my cout command i think and i dont know why ... it probably reeallly simple.. could u lead me in the right path
#include <stdlib.h>
#include <iostream>
usingnamespace std;
int order;
float billamt; // short for bill's amount
int f; // varabile to stop loop
float Vat; // to calculate vat
float total; // to add vat to bill amount or subtotal
int menuz () //function named "menuz"
{
cout << "Welcome To Evol Restaurant & Bar" <<endl;
cout << "Please Select an Option" <<endl <<endl;
cout << "\t EVOL's MENU" <<endl;
cout << "1. Burger with Fries... $13.00" <<endl;
cout << "2. Burger with Jacket Potatoes... $15.00" <<endl;
cout << "3. Spagettii.. $11.00" <<endl;
cout << "4. Chow Mein with Pop Chicken.. $14.00" <<endl;
cout << "5. Kid'z Hot-Dogs... $8.00" <<endl;
}
int main()
{
menuz (); //calling function "menuz"
do
{ cin >> order;
if (order == 1) // when user press 1
billamt += 13.00; // billamt = billamt + 13.00
if (order == 2)
billamt += 15.00;
if (order == 3)
billamt += 11.00;
if (order == 4)
billamt += 14.00;
if (order == 5)
billamt += 8.00;
} while (order != f); // f is the letter i want to stop tbe loop with
Vat = billamt * 0.175;
total = billamt + Vat;
cout << "Your Current Subtotal is... $" << billamt; // here my problem i assume the program is working but this isnt beening excuted
cout << "Your Final Bill is... $" <<total <<endl; // this is also not being excuted
system ("PAUSE");
return (0);
}
I am also new here but all I think is that your code is ok.. exept you can change int to void but that should not be problem to execute last two cout... I think you are pressing f after you are done billing and you used integer for f so if you press 0 or other key it should work as you want. is that your problem?? and i would also use switch statment rather than so many if but it is your program and it works like this fine.. i hope i helped...
On a side note. You're declaring your variables in the global scope.
As you only use these within the main() function, declare these within main();
1 2 3 4 5 6 7 8 9 10 11 12
int main()
{
int order;
float billamt; // short for bill's amount
int f; // varabile to stop loop
float Vat; // to calculate vat
float total; // to add vat to bill amount or subtotal
//code...
return 0;
}
By declaring these outside of main(), other functions can change the values! This could result in unwanted behavior.
Also. If you're going to set a value that cannot be changed, i.e., your value of f, which is the way to exit the loop.
Declare this as constint f = 0;. If something were to change this value, then your program will loop indefinitely.
first you need to set your int variable f to a default value and make it constant just in case:
const int f = 0;
THEN you need to change your menuz function to void as it doesn't return a value:
void menuz()
{}
FINALLY (and this is the most important) you need to change your while statement to this:
while(order == f);
the reason why you don't want !=(not equals) is because you are telling the program to loop as long as order does not equal 0 (what we set f to). When the user types in a 1, 2, 3, 4, or 5 then the variable order changes to either 1, 2, 3, 4, or 5 thus making order != f, so the loop continues.
Lynx876, - You Showed and Taught me alot dude thankz a grand!! :I
Hayfrend. - Umm the while (order ==f); u were trying to show me wasnt working but u helped me realise where i was going wrong with my problem with your explaination so thank ... cause the value of order would change ever time the user enter a number so thank for pointing that out for me.