Question

I learned reinforce the use of If-Else statements and while loops, how to make a project...

I learned reinforce the use of If-Else statements and while loops, how to make a project like sample run1 &2? Please explain in detail thanks. it's Introduction to C Programming use Codeblocks.

Sample Run 1

What is the price for supplier #1?

500.49

Is there another supplier to consider?

N

Supplier #1 had the best price at $500.49.

Sample Run 2

What is the price for supplier #1?

250.39 Is there another supplier to consider?

Y What is the price for supplier #2?

500.49

Is there another supplier to consider?

Y

What is the price for supplier #3?

178.72

Is there another supplier to consider?

Y

What is the price for supplier #4?

300.00

Is there another supplier to consider?

N

Supplier #3 had the best price at $178.72.

Homework Answers

Answer #1

If you have any doubts, please give me comment...

#include<stdio.h>

int main(){

    double price, best_price;

    int best_sup_no = 1, supplier_no = 1;

    char another_sup = 'Y';

    while(another_sup=='Y' || another_sup=='y'){

        printf("What is the price for supplier #%d?\n", supplier_no);

        scanf("%lf", &price);

        if(supplier_no==1)

            best_price = price;

        if(best_price>price){

            best_price = price;

            best_sup_no = supplier_no;

        }

        supplier_no++;

        printf("Is there another supplier to consider?\n");

        scanf("\n%c", &another_sup);

    }

    printf("Supplier #%d had the best price at $%g.\n", best_sup_no, best_price);

    return 0;

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In this exercise we will practice using loops to handle collections/containers. Your job is to write...
In this exercise we will practice using loops to handle collections/containers. Your job is to write a program that asks the user to enter a sentence, then it counts and displays the occurrence of each letter. Note: your program should count the letters without regard to case. For example, A and a are counted as the same. Here is a sample run: Enter a sentence: It's a very nice day today! a: 3 times c: 1 times d: 2 times...
First, watch the video "Inside the meltdown" Now let's use the AD/AS model you learned in...
First, watch the video "Inside the meltdown" Now let's use the AD/AS model you learned in chapter 10 to analyze the impact of the banking crisis on the macroeconomy.   1. First, assume that the economy was in a long-run equilibrium in spring 2008. Then, the financial turmoil started. Due to the bust of stock prices, consumer wealth declined, and consumer confidence dropped dramatically. What happened to aggregate demand? Illustrate your answer with a graph, and then explain verbally. 2. According...
Which hypothesis test do I use for this statement? It is believed that the blue team...
Which hypothesis test do I use for this statement? It is believed that the blue team is 3 inches taller than the red team. (for my data, in one column i have their heights and team color in another column) For my null and alternative hypothesis, how do I find those? I was thinking take the difference of the means since we are testing whether one team is 3 inches taller? For example, null is u1-u2= 0, alternative is u1-u2=...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Use the programming language R to code the following project.. * Make sure you turn in...
Use the programming language R to code the following project.. * Make sure you turn in your code and answers from each question. (not the raw data). 1. Generate 1000 random samples of size 40 from the normal distribution with mean µ = 3 and standard deviation σ = 2. Compute 95% the confidence interval of 1000 samples and find the rate of confidence interval contains the true mean. What did you learn from this simulation study? 2. For each...
Problem 1 ...... you can use Matlan i got one so all what i need is...
Problem 1 ...... you can use Matlan i got one so all what i need is 2, 3 and 4 one of them or all of them .. thanks The following Scilab code generates a 10-second “chirp” with discrete frequencies ranging from 0 to 0.2 with a sampling frequency of 8 kHz. clear; Fs = 8000; Nbits = 16; tMax = 10; N = Fs*tMax+1; f = linspace(0.0,0.2,N); x = zeros(f); phi = 0; for n=0:N-1 x(n+1) = 0.8*sin(phi); phi...
1- Post an experience you or someone you know had with counterfeits and how this experience...
1- Post an experience you or someone you know had with counterfeits and how this experience affected your thoughts on counterfeiting. At least a paragraph. 2- Imagine that you were setting up a small lemonade stand. There are lots of others in the neighborhood. How would you determine both your costs of production and what price to charge? (Hints: (1) Remember the profit maximizing steps discussed in the text; (2) Be sure to distinguish between fixed and variable costs.(3) This...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm to work along with a worked exercise from Chapter 5. Use two different looping strategies for different purposes. Prior Task Completion: 1. Read Chapter 05. 2. View Chapter 05’s video notes. 3. As you view the video, work along with each code sample in PyCharm using the Ch 5 Iteration PPT Code Samples.zip. Important: Do not skip the process of following along with the...
THIS IS THE GENERAL EQUILIBRIUM PROBLEM THAT I PROMISED. YOU FIRST SOLVE FOR THE INITIAL EQUILIBRIUM...
THIS IS THE GENERAL EQUILIBRIUM PROBLEM THAT I PROMISED. YOU FIRST SOLVE FOR THE INITIAL EQUILIBRIUM AS POINT A. WE CONSIDER TWO DIFFERENT AND SEPARATE SHOCKS (I CALL THEM SCENARIOS). THE FIRST SHOCK IS TO THE IS CURVE, THE SECOND SHOCK IS A ‘LM’ SHOCK. AGAIN, WE CONSIDER THESE SHOCKS SEPARATELY SO THAT AFTER YOU COMPLETE SCENARIO 1 (THE IS SHOCK), WE GO BACK TO THE ORIGINAL CONDITIONS AND CONSIDER THE SECOND SCENARIO WHICH IS THE ‘LM’ SHOCK. Consider the...
(Use C++ language) Create a program, named threeTypesLoops.cpp, that does the following; 1. Uses a For...
(Use C++ language) Create a program, named threeTypesLoops.cpp, that does the following; 1. Uses a For Loop that asks for a number between 1 and 10; Will double the number each time through the loop and display the answer. Will run five times, so the number will have been doubled five times, and the answer displayed five times. After the loop, display a message saying 'It's done!'. 2. Uses a While Loop; Ask the user to input a friend's name....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT