College Assignment help!

This is my second week of C++ course, and I have an assignment due. My instructor doesn't tell much; his teaching technique is to give few hints, and let the students do their homework.

May I have a help with coding this program?

Write a C++ program to:

Define an integer variable itotal with a value of 0
Define a real (floating) variable total with a value of 0.0
Define an integer variable five with a value of 5
Define a real (floating) variable half with a value of 0.499
Define as many character variables as you need and assign them
the letters of your first name

Use the variables above to:

Output your first name on one line
calculate half times five and assign it to itotal
calculate half times five and assign it to total
Output “five times one half is “,itotal
Output “five times one half is “,total


Thank you!
Define an integer variable itotal with a value of 0
int itotal = 0;

Define a real (floating) variable total with a value of 0.0
float total = 0.0f;

Define an integer variable five with a value of 5
int five = 5;

Define a real (floating) variable half with a value of 0.499
float half = 0.499f;

Define as many character variables as you need and assign them
the letters of your first name
char N = 'N', A = 'A', M = 'M', E = 'E'; (Edit to your own name)

Output your first name on one line
calculate half times five and assign it to itotal
calculate half times five and assign it to total
Output “five times one half is “,itotal
Output “five times one half is “,total
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
#include <iostream>

int main()
{
    int itotal = 0;
    float total = 0.0f;
    int five = 5;
    float half = 0.499f;
    char A = 'A', B = 'b', C = 'c', D = 'd', E = 'e'; //Edit to your own name!
    //or you could do char name[4] = {'N', 'A', 'M', 'E'}; but he wants variables

    //First name
    std::cout << A << B << C << D << E << std::endl;
    
    //Calculate half * five and set to itotal
    itotal = half * five;
    
    //Calculate half * five and assign to total
    total = half * five;
    
    //Output itotal
    std::cout << "five times one half is " << itotal << std::endl;
    //Output total
    std::cout << "five times one half is " << total << std::endl;
    
    return 0;
}


Good luck!
Last edited on
WOW!

So quick; it works. Thank you so much!
Topic archived. No new replies allowed.