+ 20
Cpp code problem
Anyone please tell me what's wrong here:- Question https://www.dropbox.com/s/zsia8y92o710mnu/IMG_20210127_194316.jpg?dl=0 My try : https://www.dropbox.com/s/2mmwki4n2k7li18/IMG_20210127_194344.jpg?dl=0
8 odpowiedzi
+ 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
+ 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.
+ 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🦅
+ 4
Quick Solution:
Replace the line #9 with :
cout<< percentage*arr[x]/100
and delete line #11
+ 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.
+ 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;
}
+ 3
Go through this code
+ 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