displaying characters per line and checking prime numbers

This is a discussion on displaying characters per line and checking prime numbers within the C++ Programming forums, part of the General Programming Boards category; so i have a project for my class that has to have the user specify how many characters per line ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    24

    displaying characters per line and checking prime numbers

    so i have a project for my class that has to have the user specify how many characters per line they want the alphabet to be displayed (1-26). thats where im lost. then the second part is that i have to check to see if a number is a prime number. i have to use "for" statements for both of them. please help.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    So how much of it can you do?
    Don't just post your assignment without any effort on your part.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    24
    i dont even know where to start.. i just need something to go from. i dont want my assignment done for me i just need a starting point

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    How about beginning with displaying the alphabet in any style you choose?

    Then post that so we can see where you're at, and guide you to the next level.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    24
    Code:
    	
    	int c,cpl,pn,sd,vb;
    
    	cout << "\n1) Print the alphabet using a specified number of characters per line.";
    	cout << "\n2) Check to see if a number is prime.";
    	cout << "\n3) Get the sum of the digits.";
    	cout << "\n4) Check to see if the number is a valid base.";
    	cout << "\n5) Exit\n";
    	cout << "Choice: ";
    	cin >> c;
    	switch(c){
    	case 1:
    		cout << "How many characters per line? ";
    		cin >> cpl;
    		cout <<"a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z" << endl;break;
    	case 2:
    		cout << "Enter a number to check if it is a prime number.";
    		cin >> pn;
    		cout << "You want to see if " << pn << " is prime." << endl; break;
    I'm going to need to use a for loop for both of these options but as to the logic that im going to use im clueless
    Last edited by xclarkiex5x; 10-13-2007 at 09:51 PM. Reason: forgot tags

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    Consider this snippet.
    Code:
    #include <iostream>
    #include <string>
    
    int main ( ) {
        std::string a = "abcd";
        for ( int i = 0 ; i < a.length(); i++ ) {
            std::cout << a[i] << std::endl;
        }
        return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Ideas for error checking from command line
    By NuNn in forum C Programming
    Replies: 8
    Last Post: 01-16-2009, 05:55 AM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21