Help Please Tell Me What have i Missed




This is homework I had the code correct but my computer destroyed it now I have to start over please help.


Problem 2.19 (Arithmetic, Smallest, and Largest), page 63.
 
Problem 3.15 (Sales Commission Calculator), page 109.



#include <iostream>
using std::cout;
using std::cin;
using std::endl;

void problems_2_19()

int main()
{
for (int x = 0; x < 10; x++)
{
int: num1, num2, num3, smallest, largest; //declaration
cout << "n\Input three different integers:"; //prompt
cin >> num1 >> num2 >> num3; //input
largest = num1; //assume first number is largest
{
if (num2 > largest); //is num2 larger?
largest = num2;
}
smallest = num1;//assume first number is the smallest
if (num2 < smallest)
smallest = num2;

if (num3 < smallest)
smallest = num3;

cout << "n\Sum is" << num1 + num2 + num3 << "\n Average is" << (num1 + num2 + num3) / 3;
cout<< "n\Product is" << num1*num2*num3 << "\n Smallest is" << smallest;
cout<< "n\Largest is" << largest << end1;
return 0;
}
void problems 3_15()


#include <iostream>
using std::cout;
using std::cin;
using std::ios;
using std::endl;
using namespace std;
#include <iomanip>
using std::setprecision;
using std::setiosflags;

int main()
{
float wage;
float salary;
float s;
int x = 0;

while (x < 10) {
cout << x << end1;
x++
}
cin.get();
}
for (int x = 0; x < 10; x++) {
cout << x << end1;
}
cin.get();
}
double sales= 0.0;
cout << "n\Enter sales in dollars (-1 to end)";
<< setiosflags(ios::fixed | ios::showpoint);

cout << "n\Enter sales(-1 to end)";
cin >> sales;
while (sales != -1)
wage = 200.0 + 0.09 * sales;
cout << "n\Salary is: s" << setprecision(2) << wage;
cout << "n\Enter sales in dollars (-1 to end):";
cin >> sales;
}
return 0;
{

Please, always use codetags (the <> formatting button) when posting code. It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
Your code for problem 2-19 will fail if the largest number is num3. Knowing this, you should be able to figure out why.

The code for 3.15 won't even compile. Try indenting the code to match the braces and you'll see where many of the problems are. Also:
- end1 is undefined. You mean endl (ending in lower case el instead of numeral one)
-= n\ should be \n
- The first 2 while loops just print the numbers 0-10. Is that intentional?
An easier way is to use functions to determine the min and max value. The STL has functions for that, but in case if you are not allowed to use them they are easy to implement.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>

using std::cin;
using std::cout;

int MinVal(const int a, const int b)
{
  if (a < b) // short from return a < b ? a : b; 
    return a;

  return b;
}

int MaxVal(const int a, const int b)
{
  if (a > b)
    return a;

  return b;
}

int main()
{
  int num1, num2, num3;
  cout << "Enter 3 numbers: ";
  cin >> num1 >> num2 >> num3;

  cout << "\nMin: " << MinVal(num1, MinVal(num2, num3));
  cout << "\nMax: " << MaxVal(num1, MaxVal(num2, num3));
  cout << "\n\n";
  system("pause");
  return 0;
}
Topic archived. No new replies allowed.