LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-27-2015, 10:59 PM   #1
chilla101
LQ Newbie
 
Registered: Oct 2015
Posts: 7

Rep: Reputation: Disabled
C++ newbie i really need some help debugging a program


The program is meant to give you the amount of odd and even numbers between to positive integers and print out all of the Prime numbers and tell you how many prime numbers there are.

Code:
#include<iostream>
using namespace std;
int main()
{
int n;
int startNumber;
int endNumber;
int count;
int evenCounter= 0;
int oddCounter= 0;

cout << " Please enter your starting number followed by your ending number " << endl;
   cin>> startNumber;
   cin>> endNumber;
while (startNumber <= endNumber)//beginning of the condition
{
   if (startNumber  2==0)
   evenCounter++;

 else if (startNumber !=0)
{
 oddCounter++;
 startNumber++;
{
cout << "The prime numbers between " << startNumber << " and " << endNumber << " are: " << endl;
for (n = startNumber; n <= endNumber; n++){
    count = 0;
 for (int i = 2; i <= n/2; i++){
    if(ni==0){
    count++;
}
}
if(count==0 && n!=1)
{
    cout << n << endl;
}
    }
}
 //end of the condition

cout << "The number of odd number is " << oddCounter<< endl;
cout << "The number of even number is " << evenCounter<< endl;
}
}
return 0;
}

Last edited by chilla101; 10-27-2015 at 11:01 PM.
 
Old 10-28-2015, 12:16 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Before debugging, please fix every errors and warnings the compiler gives you. If you cannot do that, quote the complete message.
 
Old 10-29-2015, 12:11 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I second Nevemteve's suggestion as well as add that you should qualify some of the test criterion where you've found problems. Also if you're having difficulties compiling and running at all, then cut/paste that information and illustrate the parts where you are stuck.

Based on a quick look you have typo's in lines 17 and 29. Fix those.

Don't alter your input numbers if you need to retain those for output or reference later in your program, instead make copies of them for modification.

Last edited by rtmistler; 10-29-2015 at 12:25 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Debugging a GFortran program. AlexBB Linux - Newbie 12 11-09-2014 04:00 PM
C program - RTLD - Help with Debugging nikunjbadjatya Programming 1 03-23-2011 10:22 PM
Debugging an exexutable C program akm3 Programming 6 12-18-2008 10:45 AM
Help with debugging Pascal program wanted. Doctorzongo Programming 4 04-13-2008 05:11 PM
Debugging Multithreaded Program villie Programming 2 08-17-2004 11:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration