STDAFX.H Problem

I'm getting an error at line 4 and 34 regarding stdafx.h


Write a program that lets the user enter a charge account number. Be sure to include comments throughout your code where appropriate. The program should determine if the number is valid by checking for it in the following list of valid account numbers:

8149420
5333174
3080098
6755963
9526981
4449539
9387197
5104726
2931356
4282637
1750219
6086650
3164838
2419590
4578589
9718904
6749941
2545408

Initialize a one-dimensional array with these values. Then use a simple linear search to locate the number entered by the user. If the user enters a number that is in the array, the program should display a message indicating that the account number is valid. If the user enters a number not in the array, the program should display a message indicating it is invalid.

Next, using the same one-dimensional array, use a bubble-sort to put the array in order and perform a binary search to locate the number entered by the user. If the user enters a number that is in the array, the program should display a message indicating that the account number is valid. If the user enters a number not in the array, the program should display a message indicating it is invalid.

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
35
  //Charles Blackwell Module 9 Assignment
#include <iostream>
#include <string>
#include "stdafx.h"
using namespace std;

const int number_elements = 18;
bool searchArray(int, int[number_elements]);
int main() {
    int Charge[] = { 8149420, 5333174, 3080098, 6755963, 9526981,
4449539, 9387197, 5104726, 2931356, 4282637, 1750219, 6086650,
3164838, 2419590, 4578589, 9718904, 6749941, 2545408 };
    int Charge_Number = 0;
    bool found = 0;

    cout << "Please enter the charge account number: " << endl;
    cin >> Charge_Number;

    if (found == searchArray(Charge_Number, Charge))
        cout << "\nCharge Account" << Charge_Number << " is a valid account" << endl;
    else
        cout << "\nCharge Account" << Charge_Number << " Is not a valid charge account" << endl;

    return 0;
}

bool searchArray(int entrednumber, int lookuparray[number_elements])
{
    for (int i = 0; i < number_elements; i++)
    {
        if (entrednumber == lookuparray[i])
            return true;
    }
    return false
}
And... what is the error? Errors are important; read them and try to understand them.

Try just deleting line 4. stdafx.h was the old way of doing precompiled headers in VS.

For line 34, you're missing a semi-colon.
Last edited on
Thank you i deleted line 4
Hello cblack618,

It has been awhile since I have used VS2015, but I do remember reading somewhere, I think it was in a Microsoft doc somewhere, that the "stdafx.h" file needs to be the first include file in any ".cpp" file.

At least that is the way it seemed to work for me and my VS2015.

Ganado's suggestion of deleting the file could work, but it is only half of the process.

The properties for the project are still set up to use precompiled headers. This will need to be changed.

This is from my VS2017, but should still be the same as VS2015 or very close.

I started by clicking on the "Solution Explorer" tab. The first line is the solution name and the second line is the project name. The project name should be highlighted, if not click on the project name.

From there you can either right click and choose properties, (bottom of the drop down box), or click on the wrench at the top.

From the window that opens navigate to "C/C++" -> "Precompiled Headers". On the line that says "Precompiled Headers" click on the down arrow and choose "Not Using Precompiled Headers" then press OK.

This will allow you to delete the "stdafx.h" file without causing any new problems.

The better way is to create an empty solution/project from the start. Then you do not have to deal with the "stdafx.h" file or changing the propertys every time.

Andy
Topic archived. No new replies allowed.