Void pointers

Looking for pointers on how to solve this question.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Exercise 11
Write the definition of a function that takes as input a char value, and returns true if the
character is a whitespace character; otherwise it returns false.

If the character is a whitespace character ouput the following message:
The character you entered is a whitespace character, 
othersise output: The character you eneted is not a whitespace character.

Exercise 14
Write the definition of a function that takes as input three numbers. 
The function returns true if the floor of the product of the first two numbers 
equals the floor of the third number; otherwise it returns false.
(Assume that the three numbers are of type double.) 
Output the appropriate message: 
The product of the first two numbers is not equal to the floor of the third number
or
The product of the first two numbers is equal to the floor of the third number



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
#include <iostream>
#include <ctype.h> 
#include <stdio.h> 
#include <cmath> 
using namespace std;

// define voids
void whitespace();
void floorcheck();
    
int main() 
{
    
// input voids
   
void whitespace();
void floorcheck();    
    
    return 0;
}

//Exercise  11
void whitespace()
{
    // taking input 
    char letter >> letter >> letter;
    cin.get(letter);
    
    // checking is it space
    if (isspace(letter)) 
        printf("\nThe character you entered is a whitespace character"); 
    else
        printf("\nThe character you entered is not a whitespace character");
    void floorcheck();
}
//Exercise 14
void floorcheck()
{
    double first;
    double second;
    double third;
    if () 
        printf("The product of the first two numbers is not equal to the floor of the third number"); 
    else
        printf("The product of the first two numbers is equal to the floor of the third number");
    
}
Last edited on
what do those questions have to do with void pointers?!
a void pointer is just an unknown type, eg void* vp; cout << (char*) vp; //you have to turn it back into something you can work with. Its less used in c++ these days.

void floorcheck(); this does not belong on line 34. This may be tripping you up, delete it.

floor() is a function in c++. Just like isspace(). Just use that in your if statement.

you are on the right track and looking good. I think you can do this, but if you can't from here, ask again.
Last edited on
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
#include <iostream>
#include <cctype>
#include <cmath>

// Write the definition of a function that takes as input a char value, and returns
// true if the character is a whitespace character; otherwise it returns false.
bool is_white_space( char c )
{
    // https://en.cppreference.com/w/cpp/string/byte/isspace
    const unsigned char u = c ;
    return std::isspace(u) ;
}

// Write the definition of a function that takes as input three numbers.
// The function returns true if the floor of the product of the first two numbers
// equals the floor of the third number; otherwise it returns false.
// (Assume that the three numbers are of type double.)
bool floor_sum_eq( double first, double second, double third )
{
    // https://en.cppreference.com/w/cpp/numeric/math/floor
    return std::floor(first*second) == std::floor(third) ;
}

int main()
{
    char ch ;
    std::cout << "enter a character: " ;
    std::cin >> ch ;

    // If the character is a whitespace character ouput the following message:
    // The character you entered is a whitespace character,
    // otherwise output: The character you entered is not a whitespace character.
    std::cout << "The character you entered is " ;
    const bool is_ws = is_white_space(ch) ;
    if( !is_ws ) std::cout << "not " ;
    std::cout << "a whitespace character.\n" ;

    // TO DO:
    // accept three numbers as input
    // Output the appropriate message:
    // The product of the first two numbers is not equal to the floor of the third number
    // or
    // The product of the first two numbers is equal to the floor of the third number
    // (call the function)
}
ok took some work and thanks to both of yall and some modifications I was able to get the program to finally accept the input.
final code becomes this:

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
#include "pch.h"
#include <iostream>
#include <cctype>
#include <cmath>
using namespace std;

//Exercise  11
//Write the definition of a function that takes as input a char value, 
//and returns true if the character is a whitespace character; otherwise it returns false.
//If the character is a whitespace character ouput the following message : 
//The character you entered is a whitespace character, 
//otherwise output : The character you eneted is not a whitespace character.
bool is_white_space(char c)
{
	const unsigned char u = c;
	return isspace(u);
}

//Exercise 14
//Write the definition of a function that takes as input three numbers.
//The function returns true if the floor of the product of the first 
//two numbers equals the floor of the third number; otherwise it returns false. 
//(Assume that the three numbers are of type double.) Output the appropriate message: 
//The product of the first two numbers is not equal to the floor of the third number
//or
//The product of the first two numbers is equal to the floor of the third number
bool floor_sum_eq(double first, double second, double third)
{
	return floor(first*second) == floor(third);
}

int main()
{
	// checking whitespace
	char ch;
	cout << "enter a character: ";
	cin.get(ch);
	const bool is_ws = is_white_space(ch);
	if (!is_ws) cout << "The character you entered is not a whitespace character";
	else cout << "The character you entered is a whitespace character";

	//floor  
	double first, second, third;
	cout << "\nenter 3 numbers ";
	cin >> first;
	cin >> second;
	cin >> third;
	
	const bool floor_sum = floor_sum_eq(first, second,  third);
	if (!floor_sum) cout << "The product of the first two numbers is not equal to the floor of the third number";
	else cout << "The product of the first two numbers is equal to the floor of the third number";

	return 0;
}



I want to thank you both for being very helpful, as a newbie this stuff gets so confusing very fast.

Topic archived. No new replies allowed.