Thread: Homework c for engineers

  1. #1
    Registered User
    Join Date
    Mar 2018
    Posts
    18

    Homework c for engineers

    OK so this is my homework , this is the first time I take a c for engineers class .
    It is the year 2035, the MarsX Space Vehicles Company has recently made its X-2 single use Space Transportation Systems (STS) available to the general public. Anyone can purchase the STSs to travel to the nearest celestial bodies (government permits and fees not included). The company has asked you to write a program that calculates the amount (in $) the customers owe for the purchase of the STSs. First, your program should welcome the customer with some fancy message (be creative). Then, the program must present the customer with a menu with two options as follows:
    Please Enter One of the Following:
    Purchase X-2 STS
    Quit
    If the customer chooses option 1, prompt him/her asking how many STSs he/she would like to purchase AND if he/she is a member of the Interplanetary Travelers Club. Display the amount he/she owes, including some fancy thank you message, keeping the following in mind:
    If customer purchases 4 STSs or less, the cost of each STS is $1.0 * 107.
    For all purchases above 4 STSs (5 and above), the cost of each STS is $8.0 * 106.
    If the customer is a member of the Interplanetary Travelers Club, he/she receives an extra 10% discount and free fuel for one of the STSs (make sure to display a message informing the customer of this).
    Customers cannot be allowed to enter a number smaller than 1.
    The program will redisplay the menu until the customer enters option 2 (Hint: use do…while loop).
    If the customer enters option 2, Quit the program.
    Validate for incorrect inputs (Hint: use while loops). If the user enters incorrect answers 5 times quit the program.
    Enjoy!



    Sample outputs (please don’t make yours exactly like this one, use some creativity):
    **************************************************
    ***** Welcome to MarsX Space Vehicles Online Store *****
    **************************************************
    Please Enter One of the Following:
    Purchase MXSV-2 STS
    Quit
    1 [Enter]
    How Many MXSV-2 STSs Would You Like to Purchase?
    10 [Enter]
    Are You a Member of the Interplanetary Travelers Club (y/n)?
    y [Enter]
    Thank You for Your Purchase: Your Total is $72,000,000.00. You Saved $8,000,000.00 Today!!!
    *** You Get Free Fuel for One of Your STSs ***
    Your free fuel voucher will arrive with the delivery of your first STS.

    Please Enter One of the Following:
    Purchase MXSV-2 STS
    Quit
    2 [Enter]
    Press any key to continue …


    -------------------------------------------------
    This is what I Have so far , I need this with printf, scanf, and if statements .I don't know how to do the if statements. Thank you!!

    #incude <stdio.h>


    int main (void)
    {
    int option;
    unsigned SpaceVehicleQuantity;
    double totalCost;

    printf("Welcome to MarsX online store\n\n");
    printf("Where shopping is always fun\n\n");
    printf("%s""1 - Purchase MXSV-2 STSs\n");
    printf("%s""2 - Quit and miss a life time experience!\n\n");
    printf("Please enter one of the following options");
    scans_s("%d" , &option);

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    Your code looks like C, not C++.


    Write the program in steps, making each step runnable and therefore testable.

    * The first step could be the "do...while" loop that just displays the menu and loops until the customer enters option 2.

    * Then you would add the "if" inside the loop to see if the customer entered option 1, and if he did then display "how many STSs?" and then maybe just print "you ordered %d STSs" printing the number that they entered.

    * Then you can add the next question (about the club) and save that answer in a boolean.

    * Then you can do the calculations.


    Try the first step and post back.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Mar 2018
    Posts
    18
    Really this is the first time I'm doing something like this I, if you could give me an example I would really appreciate it ?

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    We're not going to do your homework completely for you. Try taking the assignment in piecemeal like john.c said. First write a loop that only exits if the user entered option 2. Then gradually make it more complicated, until you've made all the calculations work and displayed all the fancy messages.

  5. #5
    Registered User
    Join Date
    Mar 2018
    Posts
    18
    I didn't ask for him to do my homework I asked for an example with the while loop , because this is the first time I do this.

  6. #6
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    It's just something like this
    Code:
    do
    {
    
    } while (option != 2);
    Indent the menu displaying/handling code inside the do...while loop.
    Try compiling/running it.
    It should loop until you enter 2.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  7. #7
    Registered User
    Join Date
    Mar 2018
    Posts
    18
    Ok thank you , that worked perfect , now you said in the beginning to add the "if" to see if the customer chose option one.
    do

    Code:
    {
          if (option !=1);
    }while (option !=2);
    under the if would I put printf and the question of "how many sts?"
    ps:I am sorry if I am asking too many questions , I wouldn't be asking If I wasn't struggling so bad.

  8. #8
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    The overall structure would be something like this:
    Code:
    #include <stdio.h>
    
    int main()
    {
        VARIABLES
    
        PRINT HELLO MESSAGE
    
        do
        {
            PRINT MENU
            READ OPTION
    
            if (option == 1)
            {
                HOW MANY SHIPS?
                READ QUANTITY
    
                IN THE CLUB?
                READ Y OR N
                
                CALCULATE
                
                DISPLAY RESULT
            }
    
        } while (option != 2);
    
        PRINT GOODBYE MESSAGE
        
        return 0;
    }
    But you should get the program without the "if" running first.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  9. #9
    Registered User
    Join Date
    Mar 2018
    Posts
    18
    Ok so ive done everything up to the calculation and everything has worked fine! how would I do the calculations? would I put something like totalCost =?

  10. #10
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    Right, you'll need a variable to hold the cost that you calculate.

    You'll need to use a couple more if's, too.

    If the quantity is 4 or less, the ships cost 1.0e7 (1 times 10 to the power 7, or 10 million) per unit.

    If you order more than 4 ships, the first 4 are at that previous price and any additional units are at the discounted price of 8.0e6 (8 million).

    Then, if he's in the club you discount the cost by 10 percent (which you can do by multiplying it by 0.9), and print a message saying that he got the discount.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  11. #11
    Registered User
    Join Date
    Mar 2018
    Posts
    18
    Thank you so much for your help, I was able to finish ,everything worked. Wouldn't have been able to do it without your help and patience!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. women explained by engineers
    By happyclown in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 03-13-2009, 05:46 PM
  2. Looking for SW Engineers with expertise in C++
    By Chipshot in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 08-21-2006, 02:49 PM
  3. Pay Rates Software Engineers
    By xddxogm3 in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 06-13-2005, 11:01 AM
  4. What exactly do quality assurance engineers do?
    By Terrance1 in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 06-05-2003, 11:23 AM
  5. Are programmers engineers?
    By joshdick in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 04-01-2003, 01:55 AM

Tags for this Thread