#include<iostream>
#include<sstream>
#include<fstream>
usingnamespace std;
int main()
{
int grade1[3];
int grade2[3];
int grade3[3];
ifstream infile;
infile.open("example1.txt");
int num = 0;
double sum = 0;
while (!infile.eof()) // <--- May have been "while (!(infile,eof())"
{
infile >> grade1[num];
infile >> grade2[num];
infile >> grade3[num];
sum = grade1[num] + grade2[num] + grade3[num];
++num;
}
cout << "The Average is: " << sum / 9 << endl;
infile.close();
return 0; // <--- Not required, but makes a good break point.
}
Answer to the OP.
Yes I could,but it would not do you any good.
Maybe you should try the jobs section.
Furry Guy wrote:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <cctype>
#include <limits>
int main()
{
std::cout << "Do you want someone to do all the work for you? ";
char answer{};
std::cin >> answer;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if (std::toupper(answer) == 'Y' ) { std::cout << "Post it in the Jobs section.\n"; }
else { std::cout << "Show what you have coded so far.\n"; }
std::cout << "Good luck.\n";
}
Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
What error?
What does it actually say. Post the whole error message.
Look at what your compiler tells you #include <iostream>; // <==== remove that last semi-colon
Your prototype: void tipcalc(int people, float bill, float tip, float& totaltip, float total);
Your definition: void tipcalc(int people, float bill, float tip, float& totaltip, float& total)
Spot the one extra character (the second &) in the definition? You need that in the prototype as well, or the main() program won't find the required function.
#include <iostream> // <--
usingnamespace std;
void tipcalc (int, float, float, float&, float&); // <--int main ()
{
int people;
float bill, tip, totaltip, total{};
cout << "how mucht is the bill ? ";
cin >> bill;
cout << "how many people will be splitting the bill? :";
cin >> people;
cout << "What is the percentage of the tip? ";
cin >> tip;
tipcalc(people, bill, tip, totaltip, total);
cout << endl;
cout << "The total tipi at " << tip << "% is $" << totaltip << '.'<< endl;
cout << "each person will pay $" << total << '.' << endl;
system("pause");
}
void tipcalc (int people, float bill, float tip, float& totaltip, float& total)
{
totaltip = bill * (tip / 100.);
total = (totaltip + bill) / people;
}
A useful way to debug functions and make the prototype and definition compatible is to copy the definition (line 29) and paste it as the prototype (line 5)but remove the variable names (some prefer to leave them in, some don't for a number of reasons)
Since you are using a floating point variable you should use "double" over "float". Even though both the "double" and "float" do not store some decimal numbers correctly the "double" is much closer to being correct. Although in a calculation using (* or /) you may still be off by 1, i.e., 1 penny.
Also prefer to use (\n) over (endl). 99+% of the time the (\n) will output everything in the output buffer.
A "cout" followed by a "cin", the "cin" will flush the output buffer before it takes in any input. Something that you can use to your advantage.