Forum > Coding >

can anyone help me type this program using functions

F34R

Fear

Posts: 216

Threads: 34

Joined: Apr, 2021

Reputation: 10

Posted

//write down a program that accepts 50 char values from user. The value can be anything char from the

key board. The program counts capitals, smalls and numeric values (0-9) separately, . It has to use a

switch structure to increment counts. It has to use an if else to decide b/w different char types It

displays the count each type at the end.

//now write it using a function, the function determines the type of the character and

returns an integer appropriately e.g. 1 for capitals, 2 for smalls, 3 for numeric values and -1 for all

others. rest of the program lies in the main.

 

 

#include <iostream>

#include <string>

using namespace std;

int main()

{

 

 

int numerical_count{};

int uppercase_count{};

int lowercase_count{};

char ch = 50;

int i;

 

 

std::string result;

 

result.resize(50); 

for (i = 0; i < 50; i++)

{

std::cin >> result[i];

 

for (const auto& ch : result)

{

 

 

if (ch >= '0' && ch <= '9')

numerical_count++;

else if (ch >= 'A' && ch <= 'Z')

uppercase_count++;

else if (ch >= 'a' && ch <= 'z')

lowercase_count++;

}

 

std::cout << "# numerical: " << numerical_count << std::endl;

std::cout << "# uppercase: " << uppercase_count << std::endl;

std::cout << "# lowercase: " << lowercase_count << std::endl;

 

 

 

}

switch (ch)

{

case '0': case '1': case '2': case '3': case '4':

case '5': case '6': case '7': case '8': case '9':

numerical_count++;

break;

case 'A': case 'B': case 'C': case 'D': case 'E':

case 'F': case 'G': case 'H': case 'I': case 'J':

case 'K': case 'L': case 'M': case 'N': case 'O':

case 'P': case 'Q': case 'R': case 'S': case 'T':

case 'U': case 'V': case 'W': case 'X': case 'Y':

case 'Z':

uppercase_count++;

break;

case 'a': case 'b': case 'c': case 'd': case 'e':

case 'f': case 'g': case 'h': case 'i': case 'j':

case 'k': case 'l': case 'm': case 'n': case 'o':

case 'p': case 'q': case 'r': case 's': case 't':

case 'u': case 'v': case 'w': case 'x': case 'y':

case 'z':

lowercase_count++;

break;

}

 

 

 

 

 

return 0;

}

 

  • 0

https://cdn.discordapp.com/attachments/1088161134621773975/1088481077401751552/Untitled.png

SeizureSalad

i love femboys

Posts: 1012

Threads: 73

Joined: Mar, 2021

Reputation: 37

Replied

What the hell

  • 0

"Questionable intellegence, but I like the mystery" - CubeFaces

https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png

Posts: 1590

Threads: 166

Joined: Apr, 2021

Reputation: 13

Replied

Excise me, have you ever heard of code blocks?

  • 0

Random quote here...

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )