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.
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;
}
Get Answers For Free
Most questions answered within 1 hours.