Thread: Help me with my two exercises.. codes

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    12

    Help me with my two exercises.. codes

    ICT02 Programming Project:
    Write a C++ program that would display the text below and will accept orders, compute for the total amount and computer for customer change after entering the given cash. The program should be looping and will end once the user answers No to the question: Another Customer (Y or N).
    SBC Restaurant
    Menu
    Item No. Item Price Item No. Item Price
    1 Fries P20 7 Mineral Water P20
    2 Hamburger P25 8 Iced Tea P40
    3 Cheese Burger P30 9 Coke P35
    4 Pizza P100 10 Sprite P35
    5 Chicken (per piece) P50 11 Sago P25
    6 Spaghetti P40 12 Taho P25

    SAMPLE OUTPUT:
    Customer Name: Jane Cruz
    Enter the Order: 1
    Quantity: 2
    Additional Order(Y or N): N

    Customer Name: Jane Cruz
    Total Amount: P40.00
    Total Cash: P50.00
    Change: P10.00

    Another Customer (Y or No): Y



    Customer Name: James Yu
    Enter the Order: 12
    Quantity: 1
    Additional Order(Y or N): Y
    Enter the Order: 6
    Quantity: 1
    Additional Order(Y or N): N

    Customer Name: James Yu
    Total Amount: P65.00
    Total Cash: P100.00
    Change: P35.00

    Another Customer (Y or No): N


    *** end of program***





    and this








    <<attachments deleted by request>> Write a C program which will compute for the average grade of a student. User will input the name of the student and his rating for each subject. The program should be able to determine the number of subjects for computation of the average. Display each student name and average grade. (Filename: EXER22)


    output should be like this... i've already solved some but having trouble with these two... HELP

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Announcements - C++ Programming
    Announcements - General Programming Boards

    You need to show some kind of effort first (attaching a picture doesn't count).

    At the least, you should be able to arrange a few cout and cin statements to do the Q&A parts, even if you're stuck on say the calculation, or making it loop on Y/N.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    12
    Quote Originally Posted by Salem View Post
    Announcements - C++ Programming
    Announcements - General Programming Boards

    You need to show some kind of effort first (attaching a picture doesn't count).

    At the least, you should be able to arrange a few cout and cin statements to do the Q&A parts, even if you're stuck on say the calculation, or making it loop on Y/N.
    im stuck here
    Code:
    #include <iostream>  #include <string>
      
      using namespace std;
    
    
      int main()
      {
          string name, section;
                      cout<<"\n\n\n\n\n\n\n";     
          cout<<"Student Name: ";
          getline(cin, name);
    
    
             float G1;
          cout<<"Grade number 1:";
          cin>>G1;
          
    
    
          
          
          
          system("PAUSE");
          return 0;
      }


    i dont know how to loop and how the calculations will go..

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Happily we can teach you how to loop:
    For, While, and Do While Loops in C++ - Cprogramming.com

    Math is going to be harder to teach. You will want to times the price by the quantity to get the food bill.

  5. #5
    Registered User
    Join Date
    Mar 2013
    Posts
    12
    i still don't get how to loop

  6. #6
    Registered User
    Join Date
    Mar 2013
    Posts
    12
    how do you delete a thread?

  7. #7
    Registered User
    Join Date
    Mar 2013
    Location
    Portugal, Porto.
    Posts
    105
    The easiest way to do this should be using arrays, but considering you barely know how to use loops I don't think you can use arrays. Can you?

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by RJ Šela Cruz View Post
    how do you delete a thread?
    OP duplicated this question in another thread, so see the reply there:
    http://cboard.cprogramming.com/cplus...ml#post1152430
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Mar 2013
    Location
    Portugal, Porto.
    Posts
    105
    Ok so I decided to give it a shot and help you out a little bit. I coded a portion of what you're looking for. I hope that's helpful.

    I haven't implemented anything for double requests, therefore it only works for single requests.
    Also, I'm not sure how is the "Total Cash" variable supposed to work. Is the user supposed to type the value he's going to pay?

    Anyway, here it is: (The code has been tested)

    Code:
    #include <iostream>
    #include <string>
    
    
    using namespace std;
    
    
    int main()
    {
    
    
        cout<<"SBC Restaurant" <<endl; 
        cout<<"Menu" <<endl <<endl <<endl;
    
    
        cout<<"Food      Item              Price | Drink     Item            Price"<<endl <<endl;    
        cout<<"1         Fries             20$   | 7         Mineral Water   20$"<<endl <<endl;
        cout<<"2         Hamburger         25$   | 8         Iced Tea        40$"<<endl <<endl;
        cout<<"3         Cheese Burger     30$   | 9         Coke            35$"<<endl <<endl;
        cout<<"4         Pizza             100$  | 10        Sprite          35$"<<endl <<endl;
        cout<<"5         Chicken(p/piece)  50$   | 11        Sago            25$"<<endl <<endl;
        cout<<"6         Spaghetti         40$   | 12        Taho            25$"<<endl <<endl <<endl <<endl;
    
    
        char answer; 
        string name;
        int norder[12], quantity, order;
        double amount, change, cash; 
    
    
        norder[0] = 20;
        norder[1] = 25;
        norder[2] = 30;
        norder[3] = 100;
        norder[4] = 50;
        norder[5] = 40;
        norder[6] = 20;
        norder[7] = 40;
        norder[8] = 35;
        norder[9] = 35;
        norder[10] = 25;
        norder[11] = 25;
    
    
        cout<<"Customer Name: ";
        cin>>name;
        cout<<"Enter the Order: ";
        cin>>order;
        cout<<"Quantity: ";
        cin>>quantity;
        cout<<"Aditional Order (Y/N): ";
        cin>>answer;
        cout<<endl;
        cin.ignore();    
    
        int price = *(norder + (order - 1));
    
        cout<<"Customer name: " <<name <<endl;
        cout<<"Total Amount: " <<price * quantity <<endl;
        cout<<"Total Cash: " <<endl;
        cout<<"Change: " <<endl <<endl;
    
        cin.get();
    }

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Don't hand out solutions. The OP has given little effort to code this him/herself.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Don't hand out solutions. The OP has given little effort to code this him/herself.
    Seconded. Especially considering the "fill in the blanks" style of code provided in post #3 - it's clear the OP really needs practice with the basics.

  12. #12
    Registered User
    Join Date
    Mar 2013
    Location
    Portugal, Porto.
    Posts
    105
    You're right, yet I only provided him with about half of the code since he was a bit lost, which means I didn't really give him a solution but just a hand.

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    A subset of the solution is still a solution in this context. The idea is not to throw code at the OP.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by Khabz View Post
    You're right, yet I only provided him with about half of the code since he was a bit lost, which means I didn't really give him a solution but just a hand.
    Your willingness to help can be a great asset to this board. In situations like this, where the OP is clearly new and inexperienced, the goal is to help them learn. Providing code is usually not the best way to go about this. It depends on the situation, though - sometimes it's clear that someone is trying their best, and taking advice, and in that scenario people are usually willing to give a little more information.

    Oftentimes, finding a solution for the question is the easy part - the difficult part is trying to find the right clues to give to the poster, so that they arrive at the solution largely by themselves.

    Of course everyone has their own style of helping - but this is the basic philosophy of these forums in regard to helping new programmers with their problems. The degree of help given should be based on the effort put forth by those who ask the questions (in this instance, it would appear that very little effort was taken to solve this problem on their own).

    But don't let criticism make you shy about contributing! It takes a bit to get the feel of this community, but just keep observing, and remember for when you help that hints can be more valuable for learning than solutions.

  15. #15
    Registered User
    Join Date
    Mar 2013
    Posts
    12
    yes... thank you very much Khabz for helping me with the first problem... now i sorta know how to do the 2nd problem... Thank you Very much.. By the way,, this isn't a assignment.. its a practice for my exams next week... THANKS KHABZ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. exercises in c++
    By BEN10 in forum C++ Programming
    Replies: 2
    Last Post: 07-26-2008, 04:07 AM
  2. C# Exercises
    By Rainbowinblack in forum C# Programming
    Replies: 0
    Last Post: 01-17-2008, 01:47 PM
  3. C++ Exercises
    By lasher in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2006, 09:48 PM
  4. Exercises
    By blankstare77 in forum C++ Programming
    Replies: 2
    Last Post: 08-31-2005, 05:46 PM
  5. converting scan codes to ascii codes
    By stupid_mutt in forum C Programming
    Replies: 11
    Last Post: 01-25-2002, 04:06 PM