C++ Programming Multiple Functions

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <stdlib.h>     
using namespace std;

void DisplayMenu(void);
void FindMilesPerGallon(void);
void TotalTime(void)
void PrimeNumber(void)

void main()
{
  int Choice;

  system("cls");

  DisplayMenu();
  cin >> Choice;
  while (Choice < 4)
    {
      switch (Choice)
        {
	      case 1: FindMilesPerGallon();
			      break;
		  case 2: TotalTime();
                  break;
		  case 3: PrimeNumber();
                  break;
		  
          default : cout << "Sorry illegal choice, Please try again\n\n";
        }
      DisplayMenu();
      cin >> Choice;

    }
}
void DisplayMenu()
{
  cout << "\n\nDo you want to:\n";
  cout << "   1) Find miles per gallon\n";
  cout << "   2) Convert total seconds to minutes and seconds\n";
  cout << "   3) Determine if number is a prime number or not\n";
  cout << "   4) QUIT\n\n";
  cout << "  CHOICE --> ";
}
void FindMilesPerGallon(void)
{
  float Miles, Gallons, Mileage;
    cout << "Enter how much gas car can hold ";
    cin >> Gallons;
    cout << "Enter how many miles till empty when full gas tank ";
    cin >> Miles;
    Mileage = Miles / Gallons;
    cout << "There is " << Mileage << "per gallon.";
}
void TotalTime(void)
{
    int Seconds, Minutes;
        cout << "Enter time in seconds";
        cin >> Seconds;
Minutes=Seconds/60; 
Seconds=Seconds%60; 
        cout << "User entered " << Minutes << "minutes and " << Seconds;
}
void PrimeNumber(void)
{
    int Integer;
  bool Prime;

  cout << "Enter a positive integer" << endl;
  cin >> Integer;

  for(int i = 3; i <= Integer; i++)
  {
    Prime = true;
    for(int n = 2; n <= i - 1; n++)
	{
      if(i % n == 0){
        Prime = false;
      }
    }
    if(Prime){
      cout << i << " is prime" << endl;
    }
  }
}



i keep getting error on this and am lost in it
Last edited on
1) Please use code tags when posting code to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) Telling us you get "an error" isn't very helpful. What possible reason could you have for not giving us more details about what error you get? Is it a compilation error? A runtime error? A crash? Unexpected behaviour?
Last edited on
I have fixed the error but i want to show if the number is prime for the last step. i do not want to show the other prime numbers up to that number. just the entered number if it is prime.
Last edited on
Topic archived. No new replies allowed.