Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › BAAAA!!! cant figure out whats wrong... C++ file
New Posts  All Forums:Forum Nav:

BAAAA!!! cant figure out whats wrong... C++ file

post #1 of 6
Thread Starter 
this little app finds prime numbers, its for an assignment for school...

i got this far... but its still not working, it wont compile....

Code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>

using namespace std;

bool isPrime(int n);
long primeCount (long x, long y);

int main()
{
    ofstream outFile;
    int Counter = 0;
    int NumberOfChiliads = 0;
    int CountLoop = 0;
    int CCount = 0;
    int TotalCnt = 0;
    float average = 0;
    
    outFile.open("a05output.txt");
    outFile << left << setw(30) << "One chiliad is 1000 numbers. ";
    outFile << left << setw(30) << "Left column is the number that starts the chiliad. ";
    outFile << left << setw(30) << "The second column is the ending number of the chiliad. ";
    outFile << left << setw(10) << "Number of Primes" << endl << endl;
    
    cout << "Enter number of Chiliads ";
    cin >> NumberOfChiliads;
    cout << endl;
    
    CCount = 1;
    cout << "Calculating primes... Please wait. If you selected a huge number, then this is going to take awhile..." << endl;
    cout << "When done, there will be a file called 'Prime.txt' in the same folder that this .exe file is in..."
    
    for (CountLoop = 1; CountLoop <= NumberOfChiliads; CountLoop++)
    {
        Counter = primeCount(CCount, CCount + 999);        
        TotalCnt = TotalCnt + Counter;                   
        
        //layout of the info going into the 'prime.txt' file
        outFile << fixed << showpoint;
        outFile << setprecision(2);
        outFile << left << setw(20) << CCount;
        outFile << left << setw(20) << CCount + 999;
        outFile << left << setw(20) << Counter << endl;
        CCount = CCount+1000;                           
    }

    outFile << "Total primes in the first " << NumberOfChiliads << " chiliads: " << TotalCnt << endl;
    cout << "Calculation complete!!!  Look for the 'prime.txt' file...." << endl << endl;

    system("PAUSE");
    return EXIT_SUCCESS;
}
bool isPrime(int n)
{
    bool bFound = false;
    int i;
    int remainder;
     
    for (i = 1; i < n; i++) 
    {
        remainder = n % i;  
        if ((n % 2) == 0)   
            return false;
        if ((i!=1) && (remainder == 0)) 
            return false;               
    }
    return true;    
}
long primeCount (long x, long y)
{
    int primeLp = 0;    
    int primeCnt = 0;   

    for (primeLp = x; primeLp < y; primeLp++)  
    {
     if (isPrime(primeLp))  
         primeCnt++;        
    }
    return primeCnt;  
}
Help?
good enough
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6600 3ghz Gigabyte GA-EP45-DS3L 9800GT 2x2gb fatility DDR2 1066 
Hard DriveOSMonitorMouse
2 x 74gb raptor raid0 win7 64bit Samsung 245BW Razer 3G diamondback 
Mouse Pad
glass core pad 
  hide details  
Reply
good enough
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6600 3ghz Gigabyte GA-EP45-DS3L 9800GT 2x2gb fatility DDR2 1066 
Hard DriveOSMonitorMouse
2 x 74gb raptor raid0 win7 64bit Samsung 245BW Razer 3G diamondback 
Mouse Pad
glass core pad 
  hide details  
Reply
post #2 of 6
Line 34

Code:
 cout << "When done, there will be a file called 'Prime.txt' in the same folder that this .exe file is in..." << endl;
It's about time!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 @3.3Ghz Gigabyte EP45-UD3P Sapphire 2900Pro Flashed to XT 4Gb Gskill 1066Mhz PK's 
Hard DriveOptical DriveOSMonitor
Seagate Barracuda 320Gb & WD Black 640Gb Lite On Vista Business and VMWare Ubuntu Acer AL2223W 22" 
KeyboardPowerCaseMouse
Ergonomic 4000 Corsair HX 620W CM 690 G5 
  hide details  
Reply
It's about time!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 @3.3Ghz Gigabyte EP45-UD3P Sapphire 2900Pro Flashed to XT 4Gb Gskill 1066Mhz PK's 
Hard DriveOptical DriveOSMonitor
Seagate Barracuda 320Gb & WD Black 640Gb Lite On Vista Business and VMWare Ubuntu Acer AL2223W 22" 
KeyboardPowerCaseMouse
Ergonomic 4000 Corsair HX 620W CM 690 G5 
  hide details  
Reply
post #3 of 6
By the way, in its current state it doesn't seem to be writing anything to "prime.txt", you currently have it set to write to a05output.txt

And some compilers don't like the phrase
Code:
system("pause");
It's about time!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 @3.3Ghz Gigabyte EP45-UD3P Sapphire 2900Pro Flashed to XT 4Gb Gskill 1066Mhz PK's 
Hard DriveOptical DriveOSMonitor
Seagate Barracuda 320Gb & WD Black 640Gb Lite On Vista Business and VMWare Ubuntu Acer AL2223W 22" 
KeyboardPowerCaseMouse
Ergonomic 4000 Corsair HX 620W CM 690 G5 
  hide details  
Reply
It's about time!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 @3.3Ghz Gigabyte EP45-UD3P Sapphire 2900Pro Flashed to XT 4Gb Gskill 1066Mhz PK's 
Hard DriveOptical DriveOSMonitor
Seagate Barracuda 320Gb & WD Black 640Gb Lite On Vista Business and VMWare Ubuntu Acer AL2223W 22" 
KeyboardPowerCaseMouse
Ergonomic 4000 Corsair HX 620W CM 690 G5 
  hide details  
Reply
post #4 of 6
Thread Starter 
Nice! i was looking so hard the "endl;" didnt register... thanks!!

In bloodshed, system("pause"); seems to work ok to me...

yeah i had to change the output file name because i had other programs that where using that same .txt file... so i changed it... guess i missed one... lol...

Anyways, thanks for the help!! +rep for you!
good enough
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6600 3ghz Gigabyte GA-EP45-DS3L 9800GT 2x2gb fatility DDR2 1066 
Hard DriveOSMonitorMouse
2 x 74gb raptor raid0 win7 64bit Samsung 245BW Razer 3G diamondback 
Mouse Pad
glass core pad 
  hide details  
Reply
good enough
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6600 3ghz Gigabyte GA-EP45-DS3L 9800GT 2x2gb fatility DDR2 1066 
Hard DriveOSMonitorMouse
2 x 74gb raptor raid0 win7 64bit Samsung 245BW Razer 3G diamondback 
Mouse Pad
glass core pad 
  hide details  
Reply
post #5 of 6
Thread Starter 
Sweet! i got it working... thanks!!
good enough
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6600 3ghz Gigabyte GA-EP45-DS3L 9800GT 2x2gb fatility DDR2 1066 
Hard DriveOSMonitorMouse
2 x 74gb raptor raid0 win7 64bit Samsung 245BW Razer 3G diamondback 
Mouse Pad
glass core pad 
  hide details  
Reply
good enough
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6600 3ghz Gigabyte GA-EP45-DS3L 9800GT 2x2gb fatility DDR2 1066 
Hard DriveOSMonitorMouse
2 x 74gb raptor raid0 win7 64bit Samsung 245BW Razer 3G diamondback 
Mouse Pad
glass core pad 
  hide details  
Reply
post #6 of 6
Simple Problem... Do you know how to troubleshoot code?
    
CPUMotherboardGraphicsRAM
Athlon 64 3700+ Sandy Biostar MATX 6100 GeForce 7600 GT 1024 MB G.SKILL PC 3200 
Hard DriveOptical DriveOSMonitor
Western Digital 160 GB ASUS DVD-RW Windows XP MCE '05, Fedora 6 17'' CRT 
PowerCase
FSP 450 Watt Black w/ Window 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Athlon 64 3700+ Sandy Biostar MATX 6100 GeForce 7600 GT 1024 MB G.SKILL PC 3200 
Hard DriveOptical DriveOSMonitor
Western Digital 160 GB ASUS DVD-RW Windows XP MCE '05, Fedora 6 17'' CRT 
PowerCase
FSP 450 Watt Black w/ Window 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › BAAAA!!! cant figure out whats wrong... C++ file