Thread: displaying characters per line and checking prime numbers

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

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, 06: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