Simple "cout " i cant fix :( help plz

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



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
#include <stdlib.h>
#include <iostream>

using namespace 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);
}
int menuz() int. Assumes you'll be returning and int.

Try changing this to void, as you don't need any values to return.
can you simplify that for me please... Do I put void command somewhere are something im a bit lost... since im not familar with the void command
Last edited on
1
2
3
4
void menuz()
{
     //code...
}


void, simply means you wont be returning value;

Whereas:
1
2
3
4
5
6
int main()
{
    //code...

    return 0;
}


int main() returns 0( an int ).
Last edited on
Sorry, I see your problem now!

You never give int f a value!

Maybe;
1
2
3
4
5
6
7
int f = 0;

int menuz ()              //function named "menuz"
{
    //code...
    cout << "Enter 0 to finish order." <<endl;
}


Then in main, add a check to see if the user wants to end the order. Making order == f.
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 const int f = 0;. If something were to change this value, then your program will loop indefinitely.
I ran your code and figured out your problem.

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.

Hope that helps you

Thankz
Mirec, - Thankz for the input :3

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.

Thankz again guyz

No problem, fella.

And hayfrend! If he did:
while order == f );

That would mean that the user would HAVE to enter the 'exit code' to keep running the program. Seeing as 'f' if the exit from the program.
Topic archived. No new replies allowed.