8 Respostas
+ 6
Right now the code prints the percentage and that's not question wants.. Do this inside for loop cout << arr[x] × 1/100 × arr[x]; I am not an expert .. see if this works
27th Jan 2021, 2:36 PM
Steve Sajeev
Steve Sajeev - avatar
+ 7
#include <iostream> using namespace std; int main() { double items []={500, 12.4, 94, 45, 3, 81, 1000.9, 85, 90, 1, 35}; int percent; double discounted_price; cin >> percent; for (int x = 0; x < 11; x++) { discounted_price=items[x]-items[x]*percent / 100; cout<<discounted_price<<" "; } return 0; } And I don't even know why you got 8 likes lol ,people should understand that it's not a social media platform and only upvote a question that is really informative and helpful for others as well.
27th Jan 2021, 2:41 PM
Abhay
Abhay - avatar
+ 5
Detailed Explanation: See on line #9 When the loop runs for first time,You are reassigning the variable percentage to the discounted price of item. Now in next iteration of loop you don't have the percentage value that user inputted as you have replaced(reasssigned) it on line #9 when loop runned for first time Cheenu🦅
27th Jan 2021, 2:44 PM
KashishAggarwal
KashishAggarwal - avatar
+ 4
Quick Solution: Replace the line #9 with : cout<< percentage*arr[x]/100 and delete line #11
27th Jan 2021, 2:40 PM
KashishAggarwal
KashishAggarwal - avatar
+ 3
you forget discount also I think issue is data type u taken int for percentage and double for items in your percentage variable values will be stored in int form may be this is the issue tell your expecting output.
27th Jan 2021, 2:44 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
#include <iostream> using namespace std; int main() { double items[]={500,12.4,94,45,3,81,1000.9,85,90,1,35}; int n,i; double percent; cin>>percent; n=sizeof(items)/sizeof(items[0]); for(i=0;i<n;i++) items[i]=items[i]-(items[i]*percent/100); for(i=0;i<n;i++) cout<<items[i]<<" "; return 0; }
27th Jan 2021, 4:17 PM
MD ZAHID
MD ZAHID - avatar
+ 3
Go through this code
27th Jan 2021, 4:17 PM
MD ZAHID
MD ZAHID - avatar
+ 2
Can anyone remove error from this code // Created by Saliha shahid #include <iostream> #include <string> #include <fstream> using namespace std; struct book { string title; string author; string publisher; int year; string isbn; book* next; book(string, string, string, int, string, book*); }; book::book(string tempTitle, string tempAuthor, string tempPublisher, int tempYear, string tempIsbn, book* tempNext) :title(tempTitle), author(tempAuthor), publisher(tempPublisher), year(tempYear), isbn(tempIsbn), next(tempNext) {} typedef book* bookPtr; void getline(istream &stream, string &str, char delimiter) { char temp[500]; stream.get(temp, 500, delimiter); stream.ignore(500, delimiter); str = temp; } void getline(istream &stream, int &num, char delimiter) { int temp; stream >> temp; stream.ignore(500, delimiter); num= temp; } void readFile(bookPtr &root); void insert (bookPtr &root); void delTitle(bookPtr
28th Jan 2021, 12:40 PM
ZOYA ZAHEER
ZOYA ZAHEER - avatar