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 trueif 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 trueif 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
#include <iostream>
#include <ctype.h>
#include <stdio.h>
#include <cmath>
usingnamespace 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");
}
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.
#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/isspaceconstunsignedchar 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/floorreturn 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 " ;
constbool 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:
#include "pch.h"
#include <iostream>
#include <cctype>
#include <cmath>
usingnamespace 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)
{
constunsignedchar 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);
constbool 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;
constbool 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.